<?php $GLOBALS['_beginTime'] = microtime(TRUE); defined('JOYEASY') or define('JOYEASY','Joyeasy'); defined('UPLOAD_PATH') or define('UPLOAD_PATH','./Uploads/'); defined('VERSION') or define('VERSION','V0.1beta'); defined('UPDATETIME') or define('UPDATETIME','20120329'); defined('APP_NAME') or define('APP_NAME','Joyeasy'); defined('APP_PATH') or define('APP_PATH','./Joyeasy/'); defined('APP_LANG') or define('APP_LANG',true); defined('THINK_PATH') or define('THINK_PATH','./Core/'); defined('MEMORY_LIMIT_ON') or define('MEMORY_LIMIT_ON',true); defined('RUNTIME_PATH') or define('RUNTIME_PATH','./Cache/'); defined('APP_DEBUG') or define('APP_DEBUG',false); defined('RUNTIME_FILE') or define('RUNTIME_FILE','./Cache/~runtime.php'); defined('THINK_VERSION') or define('THINK_VERSION','3.0'); defined('THINK_RELEASE') or define('THINK_RELEASE','20120305'); defined('MAGIC_QUOTES_GPC') or define('MAGIC_QUOTES_GPC',true); defined('IS_CGI') or define('IS_CGI',0); defined('IS_WIN') or define('IS_WIN',0); defined('IS_CLI') or define('IS_CLI',0); defined('_PHP_FILE_') or define('_PHP_FILE_','/index.php'); defined('__ROOT__') or define('__ROOT__',''); defined('URL_COMMON') or define('URL_COMMON',0); defined('URL_PATHINFO') or define('URL_PATHINFO',1); defined('URL_REWRITE') or define('URL_REWRITE',2); defined('URL_COMPAT') or define('URL_COMPAT',3); defined('CORE_PATH') or define('CORE_PATH','./Core/Lib/'); defined('EXTEND_PATH') or define('EXTEND_PATH','./Core/Extend/'); defined('MODE_PATH') or define('MODE_PATH','./Core/Extend/Mode/'); defined('ENGINE_PATH') or define('ENGINE_PATH','./Core/Extend/Engine/'); defined('VENDOR_PATH') or define('VENDOR_PATH','./Core/Extend/Vendor/'); defined('LIBRARY_PATH') or define('LIBRARY_PATH','./Core/Extend/Library/'); defined('COMMON_PATH') or define('COMMON_PATH','./Joyeasy/Common/'); defined('LIB_PATH') or define('LIB_PATH','./Joyeasy/Lib/'); defined('CONF_PATH') or define('CONF_PATH','./Joyeasy/Conf/'); defined('LANG_PATH') or define('LANG_PATH','./Joyeasy/Lang/'); defined('TMPL_PATH') or define('TMPL_PATH','./Joyeasy/Tpl/'); defined('HTML_PATH') or define('HTML_PATH','./Joyeasy/Html/'); defined('LOG_PATH') or define('LOG_PATH','./Cache/Logs/'); defined('TEMP_PATH') or define('TEMP_PATH','./Cache/Temp/'); defined('DATA_PATH') or define('DATA_PATH','./Cache/Data/'); defined('CACHE_PATH') or define('CACHE_PATH','./Cache/Cache/'); function G($start,$end='',$dec=4) { static $_info = array(); if(is_float($end)) { $_info[$start] = $end; }elseif(!empty($end)){ if(!isset($_info[$end])) $_info[$end] = microtime(TRUE); return number_format(($_info[$end]-$_info[$start]),$dec); }else{ $_info[$start] = microtime(TRUE); } } function N($key, $step=0) { static $_num = array(); if (!isset($_num[$key])) { $_num[$key] = 0; } if (empty($step)) return $_num[$key]; else $_num[$key] = $_num[$key] + (int) $step; } function parse_name($name, $type=0) { if ($type) { return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper('\\1')", $name)); } else { return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); } } function require_cache($filename) { static $_importFiles = array(); if (!isset($_importFiles[$filename])) { if (file_exists_case($filename)) { require $filename; $_importFiles[$filename] = true; } else { $_importFiles[$filename] = false; } } return $_importFiles[$filename]; } function file_exists_case($filename) { if (is_file($filename)) { if (IS_WIN && C('APP_FILE_CASE')) { if (basename(realpath($filename)) != basename($filename)) return false; } return true; } return false; } function import($class, $baseUrl = '', $ext='.class.php') { static $_file = array(); $class = str_replace(array('.', '#'), array('/', '.'), $class); if ('' === $baseUrl && false === strpos($class, '/')) { return alias_import($class); } if (isset($_file[$class . $baseUrl])) return true; else $_file[$class . $baseUrl] = true; $class_strut = explode('/', $class); if (empty($baseUrl)) { if ('@' == $class_strut[0] || APP_NAME == $class_strut[0]) { $baseUrl = dirname(LIB_PATH); $class = substr_replace($class, basename(LIB_PATH).'/', 0, strlen($class_strut[0]) + 1); }elseif ('think' == strtolower($class_strut[0])){ $baseUrl = CORE_PATH; $class = substr($class,6); }elseif (in_array(strtolower($class_strut[0]), array('org', 'com'))) { $baseUrl = LIBRARY_PATH; }else { $class = substr_replace($class, '', 0, strlen($class_strut[0]) + 1); $baseUrl = APP_PATH . '../' . $class_strut[0] . '/'.basename(LIB_PATH).'/'; } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; $classfile = $baseUrl . $class . $ext; if (!class_exists(basename($class),false)) { return require_cache($classfile); } } function load($name, $baseUrl='', $ext='.php') { $name = str_replace(array('.', '#'), array('/', '.'), $name); if (empty($baseUrl)) { if (0 === strpos($name, '@/')) { $baseUrl = COMMON_PATH; $name = substr($name, 2); } else { $baseUrl = EXTEND_PATH . 'Function/'; } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; require_cache($baseUrl . $name . $ext); } function vendor($class, $baseUrl = '', $ext='.php') { if (empty($baseUrl)) $baseUrl = VENDOR_PATH; return import($class, $baseUrl, $ext); } function alias_import($alias, $classfile='') { static $_alias = array(); if (is_string($alias)) { if(isset($_alias[$alias])) { return require_cache($_alias[$alias]); }elseif ('' !== $classfile) { $_alias[$alias] = $classfile; return; } }elseif (is_array($alias)) { $_alias = array_merge($_alias,$alias); return; } return false; } function D($name='') { if(empty($name)) return new Model; static $_model = array(); if(isset($_model[$name])) return $_model[$name]; if(strpos($name,'://')) { $name = str_replace('://','/Model/',$name); }else{ $name = C('DEFAULT_APP').'/Model/'.$name; } import($name.'Model'); $class = basename($name.'Model'); if(class_exists($class)) { $model = new $class(); }else { $model = new Model(basename($name)); } $_model[$name] = $model; return $model; } function M($name='', $tablePrefix='',$connection='') { static $_model = array(); if(strpos($name,':')) { list($class,$name) = explode(':',$name); }else{ $class = 'Model'; } if (!isset($_model[$name . '_' . $class])) $_model[$name . '_' . $class] = new $class($name,$tablePrefix,$connection); return $_model[$name . '_' . $class]; } function A($name) { static $_action = array(); if(isset($_action[$name])) return $_action[$name]; if(strpos($name,'://')) { $name = str_replace('://','/Action/',$name); }else{ $name = '@/Action/'.$name; } import($name.'Action'); $class = basename($name.'Action'); if(class_exists($class,false)) { $action = new $class(); $_action[$name] = $action; return $action; }else { return false; } } function R($url,$vars=array()) { $info = pathinfo($url); $action = $info['basename']; $module = $info['dirname']; $class = A($module); if($class) return call_user_func_array(array(&$class,$action),$vars); else return false; } function L($name=null, $value=null) { static $_lang = array(); if (empty($name)) return $_lang; if (is_string($name)) { $name = strtoupper($name); if (is_null($value)) return isset($_lang[$name]) ? $_lang[$name] : $name; $_lang[$name] = $value; return; } if (is_array($name)) $_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER)); return; } function C($name=null, $value=null) { static $_config = array(); if (empty($name)) return $_config; if (is_string($name)) { if (!strpos($name, '.')) { $name = strtolower($name); if (is_null($value)) return isset($_config[$name]) ? $_config[$name] : null; $_config[$name] = $value; return; } $name = explode('.', $name); $name[0] = strtolower($name[0]); if (is_null($value)) return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : null; $_config[$name[0]][$name[1]] = $value; return; } if (is_array($name)){ return $_config = array_merge($_config, array_change_key_case($name)); } return null; } function tag($tag, &$params=NULL) { $extends = C('extends.' . $tag); $tags = C('tags.' . $tag); if (!empty($tags)) { if(empty($tags['_overlay']) && !empty($extends)) { $tags = array_unique(array_merge($extends,$tags)); }elseif(isset($tags['_overlay'])){ unset($tags['_overlay']); } }elseif(!empty($extends)) { $tags = $extends; } if($tags) { if(APP_DEBUG) { G($tag.'Start'); Log::record('Tag[ '.$tag.' ] --START--',Log::INFO); } foreach ($tags as $key=>$name) { if(!is_int($key)) { $name = $key; } B($name, $params); } if(APP_DEBUG) { Log::record('Tag[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]',Log::INFO); } }else{ return false; } } function add_tag_behavior($tag,$behavior,$path='') { $array = C('tags.'.$tag); if(!$array) { $array = array(); } if($path) { $array[$behavior] = $path; }else{ $array[] = $behavior; } C('tags.'.$tag,$array); } function filter($name, &$content) { $class = $name . 'Filter'; require_cache(LIB_PATH . 'Filter/' . $class . '.class.php'); $filter = new $class(); $content = $filter->run($content); } function B($name, &$params=NULL) { $class = $name.'Behavior'; G('behaviorStart'); $behavior = new $class(); $behavior->run($params); if(APP_DEBUG) { G('behaviorEnd'); Log::record('Run '.$name.' Behavior [ RunTime:'.G('behaviorStart','behaviorEnd',6).'s ]',Log::INFO); } } function W($name, $data=array(), $return=false) { $class = $name . 'Widget'; require_cache(LIB_PATH . 'Widget/' . $class . '.class.php'); if (!class_exists($class)) throw_exception(L('_CLASS_NOT_EXIST_') . ':' . $class); $widget = Think::instance($class); $content = $widget->render($data); if ($return) return $content; else echo $content; } function strip_whitespace($content) { $stripStr = ''; $tokens = token_get_all($content); $last_space = false; for ($i = 0, $j = count($tokens); $i < $j; $i++) { if (is_string($tokens[$i])) { $last_space = false; $stripStr .= $tokens[$i]; } else { switch ($tokens[$i][0]) { case T_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$last_space) { $stripStr .= ' '; $last_space = true; } break; case T_START_HEREDOC: $stripStr .= "<<<THINK\n"; break; case T_END_HEREDOC: $stripStr .= "THINK;\n"; for($k = $i+1; $k < $j; $k++) { if(is_string($tokens[$k]) && $tokens[$k] == ';') { $i = $k; break; } else if($tokens[$k][0] == T_CLOSE_TAG) { break; } } break; default: $last_space = false; $stripStr .= $tokens[$i][1]; } } } return $stripStr; } function mk_dir($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return true; if (!mk_dir(dirname($dir), $mode)) return false; return @mkdir($dir, $mode); } class Think { private static $_instance = array(); static public function Start() { set_error_handler(array('Think','appError')); set_exception_handler(array('Think','appException')); spl_autoload_register(array('Think', 'autoload')); App::run(); return ; } public static function autoload($class) { if(alias_import($class)) return ; if(substr($class,-8)=='Behavior') { if(require_cache(CORE_PATH.'Behavior/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Behavior/'.$class.'.class.php') || require_cache(LIB_PATH.'Behavior/'.$class.'.class.php') || (defined('MODE_NAME') && require_cache(MODE_PATH.ucwords(MODE_NAME).'/Behavior/'.$class.'.class.php'))) { return ; } }elseif(substr($class,-5)=='Model'){ if(require_cache(LIB_PATH.'Model/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Model/'.$class.'.class.php') ) { return ; } }elseif(substr($class,-6)=='Action'){ if((defined('GROUP_NAME') && require_cache(LIB_PATH.'Action/'.GROUP_NAME.'/'.$class.'.class.php')) || require_cache(LIB_PATH.'Action/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Action/'.$class.'.class.php') ) { return ; } } $paths = explode(',',C('APP_AUTOLOAD_PATH')); foreach ($paths as $path){ if(import($path.'.'.$class)) return ; } } static public function instance($class,$method='') { $identify = $class.$method; if(!isset(self::$_instance[$identify])) { if(class_exists($class)){ $o = new $class(); if(!empty($method) && method_exists($o,$method)) self::$_instance[$identify] = call_user_func_array(array(&$o, $method)); else self::$_instance[$identify] = $o; } else halt(L('_CLASS_NOT_EXIST_').':'.$class); } return self::$_instance[$identify]; } static public function appException($e) { halt($e->__toString()); } static public function appError($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_ERROR: case E_USER_ERROR: $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行."; if(C('LOG_RECORD')) Log::write($errorStr,Log::ERR); halt($errorStr); break; case E_STRICT: case E_USER_WARNING: case E_USER_NOTICE: default: $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行."; Log::record($errorStr,Log::NOTICE); break; } } public function __set($name ,$value) { if(property_exists($this,$name)) $this->$name = $value; } public function __get($name) { return isset($this->$name)?$this->$name:null; } } class ThinkException extends Exception { private $type; private $extra; public function __construct($message,$code=0,$extra=false) { parent::__construct($message,$code); $this->type = get_class($this); $this->extra = $extra; } public function __toString() { $trace = $this->getTrace(); if($this->extra) array_shift($trace); $this->class = $trace[0]['class']; $this->function = $trace[0]['function']; $this->file = $trace[0]['file']; $this->line = $trace[0]['line']; $file = file($this->file); $traceInfo=''; $time = date('y-m-d H:i:m'); foreach($trace as $t) { $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') '; $traceInfo .= $t['class'].$t['type'].$t['function'].'('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=")\n"; } $error['message'] = $this->message; $error['type'] = $this->type; $error['detail'] = L('_MODULE_').'['.MODULE_NAME.'] '.L('_ACTION_').'['.ACTION_NAME.']'."\n"; $error['detail'] .= ($this->line-2).': '.$file[$this->line-3]; $error['detail'] .= ($this->line-1).': '.$file[$this->line-2]; $error['detail'] .= '<font color="#FF6600" >'.($this->line).': <strong>'.$file[$this->line-1].'</strong></font>'; $error['detail'] .= ($this->line+1).': '.$file[$this->line]; $error['detail'] .= ($this->line+2).': '.$file[$this->line+1]; $error['class'] = $this->class; $error['function'] = $this->function; $error['file'] = $this->file; $error['line'] = $this->line; $error['trace'] = $traceInfo; if(C('LOG_EXCEPTION_RECORD')) { Log::Write('('.$this->type.') '.$this->message); } return $error ; } } abstract class Behavior { protected $options = array(); public function __construct() { if(!empty($this->options)) { foreach ($this->options as $name=>$val){ if(NULL !== C($name)) { $this->options[$name] = C($name); }else{ C($name,$val); } } array_change_key_case($this->options); } } public function __get($name){ return $this->options[strtolower($name)]; } abstract public function run(&$params); } class ReadHtmlCacheBehavior extends Behavior { protected $options = array( 'HTML_CACHE_ON'=>false, 'HTML_CACHE_TIME'=>60, 'HTML_CACHE_RULES'=>array(), 'HTML_FILE_SUFFIX'=>'.html', ); public function run(&$params){ if(C('HTML_CACHE_ON')) { if(($cacheTime = $this->requireHtmlCache()) && $this->checkHTMLCache(HTML_FILE_NAME,$cacheTime)) { readfile(HTML_FILE_NAME); exit(); } } } static private function requireHtmlCache() { $htmls = C('HTML_CACHE_RULES'); if(!empty($htmls)) { $moduleName = strtolower(MODULE_NAME); if(isset($htmls[$moduleName.':'.ACTION_NAME])) { $html = $htmls[$moduleName.':'.ACTION_NAME]; }elseif(isset($htmls[$moduleName.':'])){ $html = $htmls[$moduleName.':']; }elseif(isset($htmls[ACTION_NAME])){ $html = $htmls[ACTION_NAME]; }elseif(isset($htmls['*'])){ $html = $htmls['*']; }elseif(isset($htmls['empty:index']) && !class_exists(MODULE_NAME.'Action')){ $html = $htmls['empty:index']; }elseif(isset($htmls[$moduleName.':_empty']) && $this->isEmptyAction(MODULE_NAME,ACTION_NAME)){ $html = $htmls[$moduleName.':_empty']; } if(!empty($html)) { $rule = $html[0]; $rule = preg_replace('/{\$(_\w+)\.(\w+)\|(\w+)}/e',"\\3(\$\\1['\\2'])",$rule); $rule = preg_replace('/{\$(_\w+)\.(\w+)}/e',"\$\\1['\\2']",$rule); $rule = preg_replace('/{(\w+)\|(\w+)}/e',"\\2(\$_GET['\\1'])",$rule); $rule = preg_replace('/{(\w+)}/e',"\$_GET['\\1']",$rule); $rule = str_ireplace( array('{:app}','{:module}','{:action}','{:group}'), array(APP_NAME,MODULE_NAME,ACTION_NAME,defined('GROUP_NAME')?GROUP_NAME:''), $rule); $rule = preg_replace('/{|(\w+)}/e',"\\1()",$rule); if(!empty($html[2])) $rule = $html[2]($rule); $cacheTime = isset($html[1])?$html[1]:C('HTML_CACHE_TIME'); define('HTML_FILE_NAME',HTML_PATH . $rule.C('HTML_FILE_SUFFIX')); return $cacheTime; } } return false; } static public function checkHTMLCache($cacheFile='',$cacheTime='') { if(!is_file($cacheFile)){ return false; }elseif (filemtime(C('TEMPLATE_NAME')) > filemtime($cacheFile)) { return false; }elseif(!is_numeric($cacheTime) && function_exists($cacheTime)){ return $cacheTime($cacheFile); }elseif ($cacheTime != 0 && time() > filemtime($cacheFile)+$cacheTime) { return false; } return true; } static private function isEmptyAction($module,$action) { $className = $module.'Action'; $class=new $className; return !method_exists($class,$action); } } class CheckRouteBehavior extends Behavior { protected $options = array( 'URL_ROUTER_ON' => false, 'URL_ROUTE_RULES' => array(), ); public function run(&$return){ $regx = trim($_SERVER['PATH_INFO'],'/'); if(empty($regx)) return $return = true; if(!C('URL_ROUTER_ON')) return $return = false; $routes = C('URL_ROUTE_RULES'); if(!empty($routes)) { $depr = C('URL_PATHINFO_DEPR'); $regx = str_replace($depr,'/',$regx); foreach ($routes as $rule=>$route){ if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { return $return = $this->parseRegex($matches,$route,$regx); }else{ $len1= substr_count($regx,'/'); $len2 = substr_count($rule,'/'); if($len1>=$len2) { if('$' == substr($rule,-1,1)) { if($len1 != $len2) { continue; }else{ $rule = substr($rule,0,-1); } } $match = $this->checkUrlMatch($regx,$rule); if($match) return $return = $this->parseRule($rule,$route,$regx); } } } } $return = false; } private function checkUrlMatch($regx,$rule) { $m1 = explode('/',$regx); $m2 = explode('/',$rule); $match = true; foreach ($m2 as $key=>$val){ if(':' == substr($val,0,1)) { if(strpos($val,'\\')) { $type = substr($val,-1); if('d'==$type && !is_numeric($m1[$key])) { $match = false; break; } }elseif(strpos($val,'^')){ $array = explode('|',substr(strstr($val,'^'),1)); if(in_array($m1[$key],$array)) { $match = false; break; } } }elseif(0 !== strcasecmp($val,$m1[$key])){ $match = false; break; } } return $match; } private function parseUrl($url) { $var = array(); if(false !== strpos($url,'?')) { $info = parse_url($url); $path = explode('/',$info['path']); parse_str($info['query'],$var); }elseif(strpos($url,'/')){ $path = explode('/',$url); }else{ parse_str($url,$var); } if(isset($path)) { $var[C('VAR_ACTION')] = array_pop($path); if(!empty($path)) { $var[C('VAR_MODULE')] = array_pop($path); } if(!empty($path)) { $var[C('VAR_GROUP')] = array_pop($path); } } return $var; } private function parseRule($rule,$route,$regx) { $url = is_array($route)?$route[0]:$route; $paths = explode('/',$regx); $matches = array(); $rule = explode('/',$rule); foreach ($rule as $item){ if(0===strpos($item,':')) { if($pos = strpos($item,'^') ) { $var = substr($item,1,$pos-1); }elseif(strpos($item,'\\')){ $var = substr($item,1,-2); }else{ $var = substr($item,1); } $matches[$var] = array_shift($paths); }else{ array_shift($paths); } } if(0=== strpos($url,'/') || 0===strpos($url,'http')) { if(strpos($url,':')) { $values = array_values($matches); $url = preg_replace('/:(\d)/e','$values[\\1-1]',$url); } header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $values = array_values($matches); foreach ($var as $key=>$val){ if(0===strpos($val,':')) { $var[$key] = $values[substr($val,1)-1]; } } $var = array_merge($matches,$var); if($paths) { preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', implode('/',$paths)); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } private function parseRegex($matches,$route,$regx) { $url = is_array($route)?$route[0]:$route; $url = preg_replace('/:(\d)/e','$matches[\\1]',$url); if(0=== strpos($url,'/') || 0===strpos($url,'http')) { header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $regx = substr_replace($regx,'',0,strlen($matches[0])); if($regx) { preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', $regx); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } } class LocationTemplateBehavior extends Behavior { public function run(&$templateFile){ if(!file_exists_case($templateFile)) $templateFile = $this->parseTemplateFile($templateFile); } private function parseTemplateFile($templateFile) { if(''==$templateFile) { $templateFile = C('TEMPLATE_NAME'); }elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){ $path = explode(':',$templateFile); $action = array_pop($path); $module = !empty($path)?array_pop($path):MODULE_NAME; if(!empty($path)) { $path = dirname(THEME_PATH).'/'.array_pop($path).'/'; }else{ $path = THEME_PATH; } $depr = defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/'; $templateFile = $path.$module.$depr.$action.C('TMPL_TEMPLATE_SUFFIX'); } if(!file_exists_case($templateFile)) throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']'); return $templateFile; } } class ParseTemplateBehavior extends Behavior { protected $options = array( 'TMPL_ENGINE_TYPE' => 'Think', 'TMPL_CACHFILE_SUFFIX' => '.php', 'TMPL_DENY_FUNC_LIST' => 'echo,exit', 'TMPL_DENY_PHP' =>false, 'TMPL_L_DELIM' => '{', 'TMPL_R_DELIM' => '}', 'TMPL_VAR_IDENTIFY' => 'array', 'TMPL_STRIP_SPACE' => true, 'TMPL_CACHE_ON' => true, 'TMPL_CACHE_TIME' => 0, 'TMPL_LAYOUT_ITEM' => '{__CONTENT__}', 'LAYOUT_ON' => false, 'LAYOUT_NAME' => 'layout', 'TAGLIB_BEGIN' => '<', 'TAGLIB_END' => '>', 'TAGLIB_LOAD' => true, 'TAGLIB_BUILD_IN' => 'cx', 'TAGLIB_PRE_LOAD' => '', ); public function run(&$_data){ $engine = strtolower(C('TMPL_ENGINE_TYPE')); if('think'==$engine){ if($this->checkCache($_data['file'])) { extract($_data['var'], EXTR_OVERWRITE); include C('CACHE_PATH').md5($_data['file']).C('TMPL_CACHFILE_SUFFIX'); }else{ $tpl = Think::instance('ThinkTemplate'); $tpl->fetch($_data['file'],$_data['var']); } }else{ $class = 'Template'.ucwords($engine); if(is_file(CORE_PATH.'Driver/Template/'.$class.'.class.php')) { $path = CORE_PATH; }else{ $path = EXTEND_PATH; } if(require_cache($path.'Driver/Template/'.$class.'.class.php')) { $tpl = new $class; $tpl->fetch($_data['file'],$_data['var']); }else { throw_exception(L('_NOT_SUPPERT_').': ' . $class); } } } protected function checkCache($tmplTemplateFile) { if (!C('TMPL_CACHE_ON')) return false; $tmplCacheFile = C('CACHE_PATH').md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); if(!is_file($tmplCacheFile)){ return false; }elseif (filemtime($tmplTemplateFile) > filemtime($tmplCacheFile)) { return false; }elseif (C('TMPL_CACHE_TIME') != 0 && time() > filemtime($tmplCacheFile)+C('TMPL_CACHE_TIME')) { return false; } if(C('LAYOUT_ON')) { $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); if(filemtime($layoutFile) > filemtime($tmplCacheFile)) { return false; } } return true; } } class ContentReplaceBehavior extends Behavior { protected $options = array( 'TMPL_PARSE_STRING'=>array(), ); public function run(&$content){ $content = $this->templateContentReplace($content); } protected function templateContentReplace($content) { $replace = array( '__TMPL__' => APP_TMPL_PATH, '__ROOT__' => __ROOT__, '__APP__' => __APP__, '__GROUP__' => defined('GROUP_NAME')?__GROUP__:__APP__, '__ACTION__' => __ACTION__, '__SELF__' => __SELF__, '__URL__' => __URL__, '../Public' => APP_TMPL_PATH.'Public', '__PUBLIC__' => __ROOT__.'/Public', ); if(is_array(C('TMPL_PARSE_STRING')) ) $replace = array_merge($replace,C('TMPL_PARSE_STRING')); $content = str_replace(array_keys($replace),array_values($replace),$content); return $content; } } class TokenBuildBehavior extends Behavior { protected $options = array( 'TOKEN_ON' => true, 'TOKEN_NAME' => '__hash__', 'TOKEN_TYPE' => 'md5', 'TOKEN_RESET' => true, ); public function run(&$content){ if(C('TOKEN_ON')) { if(strpos($content,'{__TOKEN__}')) { $content = str_replace('{__TOKEN__}',$this->buildToken(),$content); }elseif(preg_match('/<\/form(\s*)>/is',$content,$match)) { $content = str_replace($match[0],$this->buildToken().$match[0],$content); } } } private function buildToken() { $tokenName = C('TOKEN_NAME'); $tokenType = C('TOKEN_TYPE'); if(!isset($_SESSION[$tokenName])) { $_SESSION[$tokenName] = array(); } $tokenKey = md5($_SERVER['REQUEST_URI']); if(isset($_SESSION[$tokenName][$tokenKey])) { $tokenValue = $_SESSION[$tokenName][$tokenKey]; }else{ $tokenValue = $tokenType(microtime(TRUE)); $_SESSION[$tokenName][$tokenKey] = $tokenValue; } if($action = C('TOKEN_ACTION')){ $_SESSION[$action($tokenKey)] = true; } $token = '<input type="hidden" name="'.$tokenName.'" value="'.$tokenKey.'_'.$tokenValue.'" />'; return $token; } } class WriteHtmlCacheBehavior extends Behavior { public function run(&$content){ if(C('HTML_CACHE_ON') && defined('HTML_FILE_NAME')) { if(!is_dir(dirname(HTML_FILE_NAME))) mk_dir(dirname(HTML_FILE_NAME)); if( false === file_put_contents( HTML_FILE_NAME , $content )) throw_exception(L('_CACHE_WRITE_ERROR_').':'.HTML_FILE_NAME); } } } class ShowRuntimeBehavior extends Behavior { protected $options = array( 'SHOW_RUN_TIME' => false, 'SHOW_ADV_TIME' => false, 'SHOW_DB_TIMES' => false, 'SHOW_CACHE_TIMES' => false, 'SHOW_USE_MEM' => false, 'SHOW_LOAD_FILE' => false, 'SHOW_FUN_TIMES' => false , ); public function run(&$content){ if(C('SHOW_RUN_TIME')){ if(false !== strpos($content,'{__NORUNTIME__}')) { $content = str_replace('{__NORUNTIME__}','',$content); }else{ $runtime = $this->showTime(); if(strpos($content,'{__RUNTIME__}')) $content = str_replace('{__RUNTIME__}',$runtime,$content); else $content .= $runtime; } }else{ $content = str_replace(array('{__NORUNTIME__}','{__RUNTIME__}'),'',$content); } } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; if(C('SHOW_ADV_TIME')) { $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; } if(C('SHOW_DB_TIMES') && class_exists('Db',false) ) { $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; } if(C('SHOW_CACHE_TIMES') && class_exists('Cache',false)) { $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; } if(MEMORY_LIMIT_ON && C('SHOW_USE_MEM')) { $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; } if(C('SHOW_LOAD_FILE')) { $showTime .= ' | LoadFile:'.count(get_included_files()); } if(C('SHOW_FUN_TIMES')) { $fun = get_defined_functions(); $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); } return $showTime; } } class ShowPageTraceBehavior extends Behavior { protected $options = array( 'SHOW_PAGE_TRACE' => false, ); public function run(&$params){ if(C('SHOW_PAGE_TRACE')) { echo $this->showTrace(); } } private function showTrace() { $log = Log::$log; $files = get_included_files(); $trace = array( '请求时间'=> date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']), '当前页面'=> __SELF__, '请求协议'=> $_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'], '运行信息'=> $this->showTime(), '会话ID' => session_id(), '日志记录'=> count($log)?count($log).'条日志<br/>'.implode('<br/>',$log):'无日志记录', '加载文件'=> count($files).str_replace("\n",'<br/>',substr(substr(print_r($files,true),7),0,-2)), ); $traceFile = CONF_PATH.'trace.php'; if(is_file($traceFile)) { $trace = array_merge(include $traceFile,$trace); } trace($trace); ob_start(); include C('TMPL_TRACE_FILE')?C('TMPL_TRACE_FILE'):THINK_PATH.'Tpl/page_trace.tpl'; return ob_get_clean(); } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; if(class_exists('Db',false) ) { $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; } if( class_exists('Cache',false)) { $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; } if(MEMORY_LIMIT_ON ) { $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; } $showTime .= ' | LoadFile:'.count(get_included_files()); $fun = get_defined_functions(); $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); return $showTime; } }alias_import(array ( 'Model' => './Core/Lib/Core/Model.class.php', 'Db' => './Core/Lib/Core/Db.class.php', 'Log' => './Core/Lib/Core/Log.class.php', 'ThinkTemplate' => './Core/Lib/Template/ThinkTemplate.class.php', 'TagLib' => './Core/Lib/Template/TagLib.class.php', 'Cache' => './Core/Lib/Core/Cache.class.php', 'Widget' => './Core/Lib/Core/Widget.class.php', 'TagLibCx' => './Core/Lib/Driver/TagLib/TagLibCx.class.php', )); function halt($error) { $e = array(); if (APP_DEBUG) { if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['class'] = $trace[0]['class']; $e['function'] = $trace[0]['function']; $e['line'] = $trace[0]['line']; $traceInfo = ''; $time = date('y-m-d H:i:m'); foreach ($trace as $t) { $traceInfo .= '[' . $time . '] ' . $t['file'] . ' (' . $t['line'] . ') '; $traceInfo .= $t['class'] . $t['type'] . $t['function'] . '('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=')<br/>'; } $e['trace'] = $traceInfo; } else { $e = $error; } include C('TMPL_EXCEPTION_FILE'); } else { $error_page = C('ERROR_PAGE'); if (!empty($error_page)) { redirect($error_page); } else { if (C('SHOW_ERROR_MSG')) $e['message'] = is_array($error) ? $error['message'] : $error; else $e['message'] = C('ERROR_MESSAGE'); include C('TMPL_EXCEPTION_FILE'); } } exit; } function throw_exception($msg, $type='ThinkException', $code=0) { if (class_exists($type, false)) throw new $type($msg, $code, true); else halt($msg); } function dump($var, $echo=true, $label=null, $strict=true) { $label = ($label === null) ? '' : rtrim($label) . ' '; if (!$strict) { if (ini_get('html_errors')) { $output = print_r($var, true); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } else { $output = $label . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace("/\]\=\>\n(\s+)/m", '] => ', $output); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } } if ($echo) { echo($output); return null; }else return $output; } function debug_start($label='') { $GLOBALS[$label]['_beginTime'] = microtime(TRUE); if (MEMORY_LIMIT_ON) $GLOBALS[$label]['_beginMem'] = memory_get_usage(); } function debug_end($label='') { $GLOBALS[$label]['_endTime'] = microtime(TRUE); echo '<div style="text-align:center;width:100%">Process ' . $label . ': Times ' . number_format($GLOBALS[$label]['_endTime'] - $GLOBALS[$label]['_beginTime'], 6) . 's '; if (MEMORY_LIMIT_ON) { $GLOBALS[$label]['_endMem'] = memory_get_usage(); echo ' Memories ' . number_format(($GLOBALS[$label]['_endMem'] - $GLOBALS[$label]['_beginMem']) / 1024) . ' k'; } echo '</div>'; } function trace($title='',$value='') { if(!C('SHOW_PAGE_TRACE')) return; static $_trace = array(); if(is_array($title)) { $_trace = array_merge($_trace,$title); }elseif('' !== $value){ $_trace[$title] = $value; }elseif('' !== $title){ return $_trace[$title]; }else{ return $_trace; } } function layout($layout) { if(false !== $layout) { C('LAYOUT_ON',true); if(is_string($layout)) { C('LAYOUT_NAME',$layout); } } } function U($url,$vars='',$suffix=true,$redirect=false,$domain=false) { $info = parse_url($url); $url = !empty($info['path'])?$info['path']:ACTION_NAME; if($domain===true){ $domain = $_SERVER['HTTP_HOST']; if(C('APP_SUB_DOMAIN_DEPLOY') ) { $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { if(false === strpos($key,'*') && 0=== strpos($url,$rule[0])) { $domain = $key.strstr($domain,'.'); $url = substr_replace($url,'',0,strlen($rule[0])); break; } } } } if(is_string($vars)) { parse_str($vars,$vars); }elseif(!is_array($vars)){ $vars = array(); } if(isset($info['query'])) { parse_str($info['query'],$params); $vars = array_merge($params,$vars); } $depr = C('URL_PATHINFO_DEPR'); if($url) { if(0=== strpos($url,'/')) { $route = true; $url = substr($url,1); if('/' != $depr) { $url = str_replace('/',$depr,$url); } }else{ if('/' != $depr) { $url = str_replace('/',$depr,$url); } $url = trim($url,$depr); $path = explode($depr,$url); $var = array(); $var[C('VAR_ACTION')] = !empty($path)?array_pop($path):ACTION_NAME; $var[C('VAR_MODULE')] = !empty($path)?array_pop($path):MODULE_NAME; if(C('URL_CASE_INSENSITIVE')) { $var[C('VAR_MODULE')] = parse_name($var[C('VAR_MODULE')]); } if(C('APP_GROUP_LIST')) { if(!empty($path)) { $group = array_pop($path); $var[C('VAR_GROUP')] = $group; }else{ if(GROUP_NAME != C('DEFAULT_GROUP')) { $var[C('VAR_GROUP')] = GROUP_NAME; } } } } } if(C('URL_MODEL') == 0) { $url = __APP__.'?'.http_build_query($var); if(!empty($vars)) { $vars = http_build_query($vars); $url .= '&'.$vars; } }else{ if(isset($route)) { $url = __APP__.'/'.$url; }else{ $url = __APP__.'/'.implode($depr,array_reverse($var)); } if(!empty($vars)) { $vars = http_build_query($vars); $url .= $depr.str_replace(array('=','&'),$depr,$vars); } if($suffix) { $suffix = $suffix===true?C('URL_HTML_SUFFIX'):$suffix; if($suffix) { $url .= '.'.ltrim($suffix,'.'); } } } if($domain) { $url = 'http://'.$domain.$url; } if($redirect) redirect($url); else return $url; } function redirect($url, $time=0, $msg='') { $url = str_replace(array("\n", "\r"), '', $url); if (empty($msg)) $msg = "系统将在{$time}秒之后自动跳转到{$url}！"; if (!headers_sent()) { if (0 === $time) { header('Location: ' . $url); } else { header("refresh:{$time};url={$url}"); echo($msg); } exit(); } else { $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>"; if ($time != 0) $str .= $msg; exit($str); } } function S($name, $value='', $expire=null, $type='',$options=null) { static $_cache = array(); $cache = Cache::getInstance($type,$options); if ('' !== $value) { if (is_null($value)) { $result = $cache->rm($name); if ($result) unset($_cache[$type . '_' . $name]); return $result; }else { $cache->set($name, $value, $expire); $_cache[$type . '_' . $name] = $value; } return; } if (isset($_cache[$type . '_' . $name])) return $_cache[$type . '_' . $name]; $value = $cache->get($name); $_cache[$type . '_' . $name] = $value; return $value; } function F($name, $value='', $path=DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { return unlink($filename); } else { $dir = dirname($filename); if (!is_dir($dir)) mkdir($dir); $_cache[$name] = $value; return file_put_contents($filename, strip_whitespace("<?php\nreturn " . var_export($value, true) . ";\n?>")); } } if (isset($_cache[$name])) return $_cache[$name]; if (is_file($filename)) { $value = include $filename; $_cache[$name] = $value; } else { $value = false; } return $value; } function get_instance_of($name, $method='', $args=array()) { static $_instance = array(); $identify = empty($args) ? $name . $method : $name . $method . to_guid_string($args); if (!isset($_instance[$identify])) { if (class_exists($name)) { $o = new $name(); if (method_exists($o, $method)) { if (!empty($args)) { $_instance[$identify] = call_user_func_array(array(&$o, $method), $args); } else { $_instance[$identify] = $o->$method(); } } else $_instance[$identify] = $o; } else halt(L('_CLASS_NOT_EXIST_') . ':' . $name); } return $_instance[$identify]; } function to_guid_string($mix) { if (is_object($mix) && function_exists('spl_object_hash')) { return spl_object_hash($mix); } elseif (is_resource($mix)) { $mix = get_resource_type($mix) . strval($mix); } else { $mix = serialize($mix); } return md5($mix); } function xml_encode($data, $encoding='utf-8', $root='think') { $xml = '<?xml version="1.0" encoding="' . $encoding . '"?>'; $xml.= '<' . $root . '>'; $xml.= data_to_xml($data); $xml.= '</' . $root . '>'; return $xml; } function data_to_xml($data) { $xml = ''; foreach ($data as $key => $val) { is_numeric($key) && $key = "item id=\"$key\""; $xml.="<$key>"; $xml.= ( is_array($val) || is_object($val)) ? data_to_xml($val) : $val; list($key, ) = explode(' ', $key); $xml.="</$key>"; } return $xml; } function session($name,$value='') { $prefix = C('SESSION_PREFIX'); if(is_array($name)) { if(isset($name['prefix'])) C('SESSION_PREFIX',$name['prefix']); if(isset($_REQUEST[C('VAR_SESSION_ID')])){ session_id($_REQUEST[C('VAR_SESSION_ID')]); }elseif(isset($name['id'])) { session_id($name['id']); } ini_set('session.auto_start', 0); if(isset($name['name'])) session_name($name['name']); if(isset($name['path'])) session_save_path($name['path']); if(isset($name['domain'])) ini_set('session.cookie_domain', $name['domain']); if(isset($name['expire'])) ini_set('session.gc_maxlifetime', $name['expire']); if(isset($name['use_trans_sid'])) ini_set('session.use_trans_sid', $name['use_trans_sid']?1:0); if(isset($name['use_cookies'])) ini_set('session.use_cookies', $name['use_cookies']?1:0); if(isset($name['type'])) C('SESSION_TYPE',$name['type']); if(C('SESSION_TYPE')) { $class = 'Session'. ucwords(strtolower(C('SESSION_TYPE'))); if(require_cache(EXTEND_PATH.'Driver/Session/'.$class.'.class.php')) { $hander = new $class(); $hander->execute(); }else { throw_exception(L('_CLASS_NOT_EXIST_').': ' . $class); } } if(C('SESSION_AUTO_START')) session_start(); }elseif('' === $value){ if(0===strpos($name,'[')) { if('[pause]'==$name){ session_write_close(); }elseif('[start]'==$name){ session_start(); }elseif('[destroy]'==$name){ $_SESSION = array(); session_unset(); session_destroy(); }elseif('[regenerate]'==$name){ session_regenerate_id(); } }elseif(0===strpos($name,'?')){ $name = substr($name,1); if($prefix) { return isset($_SESSION[$prefix][$name]); }else{ return isset($_SESSION[$name]); } }elseif(is_null($name)){ if($prefix) { unset($_SESSION[$prefix]); }else{ $_SESSION = array(); } }elseif($prefix){ return $_SESSION[$prefix][$name]; }else{ return $_SESSION[$name]; } }elseif(is_null($value)){ if($prefix){ unset($_SESSION[$prefix][$name]); }else{ unset($_SESSION[$name]); } }else{ if($prefix){ if (!is_array($_SESSION[$prefix])) { $_SESSION[$prefix] = array(); } $_SESSION[$prefix][$name] = $value; }else{ $_SESSION[$name] = $value; } } } function cookie($name, $value='', $option=null) { $config = array( 'prefix' => C('COOKIE_PREFIX'), 'expire' => C('COOKIE_EXPIRE'), 'path' => C('COOKIE_PATH'), 'domain' => C('COOKIE_DOMAIN'), ); if (!empty($option)) { if (is_numeric($option)) $option = array('expire' => $option); elseif (is_string($option)) parse_str($option, $option); $config = array_merge($config, array_change_key_case($option)); } if (is_null($name)) { if (empty($_COOKIE)) return; $prefix = empty($value) ? $config['prefix'] : $value; if (!empty($prefix)) { foreach ($_COOKIE as $key => $val) { if (0 === stripos($key, $prefix)) { setcookie($key, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$key]); } } } return; } $name = $config['prefix'] . $name; if ('' === $value) { return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null; } else { if (is_null($value)) { setcookie($name, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$name]); } else { $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; setcookie($name, $value, $expire, $config['path'], $config['domain']); $_COOKIE[$name] = $value; } } } function load_ext_file() { if(C('LOAD_EXT_FILE')) { $files = explode(',',C('LOAD_EXT_FILE')); foreach ($files as $file){ $file = COMMON_PATH.$file.'.php'; if(is_file($file)) include $file; } } if(C('LOAD_EXT_CONFIG')) { $configs = C('LOAD_EXT_CONFIG'); if(is_string($configs)) $configs = explode(',',$configs); foreach ($configs as $key=>$config){ $file = CONF_PATH.$config.'.php'; if(is_file($file)) { is_numeric($key)?C(include $file):C($key,include $file); } } } } function get_client_ip() { static $ip = NULL; if ($ip !== NULL) return $ip; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $ip = (false !== ip2long($ip)) ? $ip : '0.0.0.0'; return $ip; } function send_http_status($code) { static $_status = array( 200 => 'OK', 301 => 'Moved Permanently', 302 => 'Moved Temporarily ', 400 => 'Bad Request', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error', 503 => 'Service Unavailable', ); if(isset($_status[$code])) { header('HTTP/1.1 '.$code.' '.$_status[$code]); header('Status:'.$code.' '.$_status[$code]); } } class Log { const EMERG = 'EMERG'; const ALERT = 'ALERT'; const CRIT = 'CRIT'; const ERR = 'ERR'; const WARN = 'WARN'; const NOTICE = 'NOTIC'; const INFO = 'INFO'; const DEBUG = 'DEBUG'; const SQL = 'SQL'; const SYSTEM = 0; const MAIL = 1; const FILE = 3; const SAPI = 4; static $log = array(); static $format = '[ c ]'; static function record($message,$level=self::ERR,$record=false) { if($record || strpos(C('LOG_LEVEL'),$level)) { $now = date(self::$format); self::$log[] = "{$now} ".$_SERVER['REQUEST_URI']." | {$level}: {$message}\r\n"; } } static function save($type='',$destination='',$extra='') { $type = $type?$type:C('LOG_TYPE'); if(self::FILE == $type) { if(empty($destination)) $destination = LOG_PATH.date('y_m_d').'.log'; if(is_file($destination) && floor(C('LOG_FILE_SIZE')) <= filesize($destination) ) rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); }else{ $destination = $destination?$destination:C('LOG_DEST'); $extra = $extra?$extra:C('LOG_EXTRA'); } error_log(implode('',self::$log), $type,$destination ,$extra); self::$log = array(); } static function write($message,$level=self::ERR,$type='',$destination='',$extra='') { $now = date(self::$format); $type = $type?$type:C('LOG_TYPE'); if(self::FILE == $type) { if(empty($destination)) $destination = LOG_PATH.date('y_m_d').'.log'; if(is_file($destination) && floor(C('LOG_FILE_SIZE')) <= filesize($destination) ) rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); }else{ $destination = $destination?$destination:C('LOG_DEST'); $extra = $extra?$extra:C('LOG_EXTRA'); } error_log("{$now} ".$_SERVER['REQUEST_URI']." | {$level}: {$message}\r\n", $type,$destination,$extra ); } } class Dispatcher { static public function dispatch() { $urlMode = C('URL_MODEL'); if(!empty($_GET[C('VAR_PATHINFO')])) { $_SERVER['PATH_INFO'] = $_GET[C('VAR_PATHINFO')]; unset($_GET[C('VAR_PATHINFO')]); } if($urlMode == URL_COMPAT ){ define('PHP_FILE',_PHP_FILE_.'?'.C('VAR_PATHINFO').'='); }elseif($urlMode == URL_REWRITE ) { $url = dirname(_PHP_FILE_); if($url == '/' || $url == '\\') $url = ''; define('PHP_FILE',$url); }else { define('PHP_FILE',_PHP_FILE_); } if(C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); $subDomain = strtolower(substr($_SERVER['HTTP_HOST'],0,strpos($_SERVER['HTTP_HOST'],'.'))); define('SUB_DOMAIN',$subDomain); if($subDomain && isset($rules[$subDomain])) { $rule = $rules[$subDomain]; }elseif(isset($rules['*'])){ if('www' != $subDomain && !in_array($subDomain,C('APP_SUB_DOMAIN_DENY'))) { $rule = $rules['*']; } } if(!empty($rule)) { $array = explode('/',$rule[0]); $module = array_pop($array); if(!empty($module)) { $_GET[C('VAR_MODULE')] = $module; $domainModule = true; } if(!empty($array)) { $_GET[C('VAR_GROUP')] = array_pop($array); $domainGroup = true; } if(isset($rule[1])) { parse_str($rule[1],$parms); $_GET = array_merge($_GET,$parms); } } } if(empty($_SERVER['PATH_INFO'])) { $types = explode(',',C('URL_PATHINFO_FETCH')); foreach ($types as $type){ if(0===strpos($type,':')) { $_SERVER['PATH_INFO'] = call_user_func(substr($type,1)); break; }elseif(!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type],$_SERVER['SCRIPT_NAME']))? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } $depr = C('URL_PATHINFO_DEPR'); if(!empty($_SERVER['PATH_INFO'])) { tag('path_info'); if(C('URL_HTML_SUFFIX')) { $_SERVER['PATH_INFO'] = preg_replace('/\.'.trim(C('URL_HTML_SUFFIX'),'.').'$/i', '', $_SERVER['PATH_INFO']); } if(!self::routerCheck()){ $paths = explode($depr,trim($_SERVER['PATH_INFO'],'/')); if(C('VAR_URL_PARAMS')) { $_GET[C('VAR_URL_PARAMS')] = $paths; } $var = array(); if (C('APP_GROUP_LIST') && !isset($_GET[C('VAR_GROUP')])){ $var[C('VAR_GROUP')] = in_array(strtolower($paths[0]),explode(',',strtolower(C('APP_GROUP_LIST'))))? array_shift($paths) : ''; if(C('APP_GROUP_DENY') && in_array(strtolower($var[C('VAR_GROUP')]),explode(',',strtolower(C('APP_GROUP_DENY'))))) { exit; } } if(!isset($_GET[C('VAR_MODULE')])) { $var[C('VAR_MODULE')] = array_shift($paths); } $var[C('VAR_ACTION')] = array_shift($paths); $res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode($depr,$paths)); $_GET = array_merge($var,$_GET); } define('__INFO__',$_SERVER['PATH_INFO']); } if (C('APP_GROUP_LIST')) { define('GROUP_NAME', self::getGroup(C('VAR_GROUP'))); } define('MODULE_NAME',self::getModule(C('VAR_MODULE'))); define('ACTION_NAME',self::getAction(C('VAR_ACTION'))); define('__SELF__',strip_tags($_SERVER['REQUEST_URI'])); define('__APP__',strip_tags(PHP_FILE)); $module = defined('P_MODULE_NAME')?P_MODULE_NAME:MODULE_NAME; if(defined('GROUP_NAME')) { define('__GROUP__',(!empty($domainGroup) || strtolower(GROUP_NAME) == strtolower(C('DEFAULT_GROUP')) )?__APP__ : __APP__.'/'.GROUP_NAME); define('__URL__',!empty($domainModule)?__GROUP__.$depr : __GROUP__.$depr.$module); }else{ define('__URL__',!empty($domainModule)?__APP__.'/' : __APP__.'/'.$module); } define('__ACTION__',__URL__.$depr.ACTION_NAME); $_REQUEST = array_merge($_POST,$_GET); } static public function routerCheck() { $return = false; tag('route_check',$return); return $return; } static private function getModule($var) { $module = (!empty($_GET[$var])? $_GET[$var]:C('DEFAULT_MODULE')); unset($_GET[$var]); if(C('URL_CASE_INSENSITIVE')) { define('P_MODULE_NAME',strtolower($module)); $module = ucfirst(parse_name(P_MODULE_NAME,1)); } return strip_tags($module); } static private function getAction($var) { $action = !empty($_POST[$var]) ? $_POST[$var] : (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_ACTION')); unset($_POST[$var],$_GET[$var]); define('P_ACTION_NAME',$action); return strip_tags(C('URL_CASE_INSENSITIVE')?strtolower($action):$action); } static private function getGroup($var) { $group = (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_GROUP')); unset($_GET[$var]); return strip_tags(C('URL_CASE_INSENSITIVE') ?ucfirst(strtolower($group)):$group); } } class App { static public function init() { date_default_timezone_set(C('DEFAULT_TIMEZONE')); load_ext_file(); Dispatcher::dispatch(); if(defined('GROUP_NAME')) { if(is_file(CONF_PATH.GROUP_NAME.'/config.php')) C(include CONF_PATH.GROUP_NAME.'/config.php'); if(is_file(COMMON_PATH.GROUP_NAME.'/function.php')) include COMMON_PATH.GROUP_NAME.'/function.php'; } $templateSet = C('DEFAULT_THEME'); if(C('TMPL_DETECT_THEME')) { $t = C('VAR_TEMPLATE'); if (isset($_GET[$t])){ $templateSet = $_GET[$t]; }elseif(cookie('think_template')){ $templateSet = cookie('think_template'); } if(!is_dir(TMPL_PATH.$templateSet)) $templateSet = C('DEFAULT_THEME'); cookie('think_template',$templateSet); } $group = defined('GROUP_NAME')?GROUP_NAME.'/':''; if($_GET['iscreatehtml']){ C('LAYOUT_ON',C('LAYOUT_HOME_ON')); $group ='Home/'; define('THEME_NAME', C('DEFAULT_HOME_THEME')); }else{ define('THEME_NAME', $templateSet); } define('THEME_PATH', TMPL_PATH.$group.(THEME_NAME?THEME_NAME.'/':'')); define('APP_TMPL_PATH',__ROOT__.'/'.APP_NAME.(APP_NAME?'/':'').basename(TMPL_PATH).'/'.$group.(THEME_NAME?THEME_NAME.'/':'')); C('TEMPLATE_NAME',THEME_PATH.MODULE_NAME.(defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/').ACTION_NAME.C('TMPL_TEMPLATE_SUFFIX')); C('CACHE_PATH',CACHE_PATH.$group); return ; } static public function exec() { if(!preg_match('/^[A-Za-z_0-9]+$/',MODULE_NAME)){ $module = false; }else{ $group = defined('GROUP_NAME') ? GROUP_NAME.'/' : ''; $module = A($group.MODULE_NAME); } if(!$module) { if(function_exists('__hack_module')) { $module = __hack_module(); if(!is_object($module)) { return ; } }else{ $module = A('Empty'); if(!$module){ $msg = L('_MODULE_NOT_EXIST_').MODULE_NAME; if(APP_DEBUG) { throw_exception($msg); }else{ if(C('LOG_EXCEPTION_RECORD')) Log::write($msg); send_http_status(404); exit; } } } } $action = ACTION_NAME; tag('action_name',$action); if (method_exists($module,'_before_'.$action)) { call_user_func(array(&$module,'_before_'.$action)); } call_user_func(array(&$module,$action)); if (method_exists($module,'_after_'.$action)) { call_user_func(array(&$module,'_after_'.$action)); } return ; } static public function run() { tag('app_init'); App::init(); tag('app_begin'); session(C('SESSION_OPTIONS')); G('initTime'); App::exec(); tag('app_end'); if(C('LOG_RECORD')) Log::save(); return ; } } abstract class Action { protected $view = null; private $name = ''; public function __construct() { tag('action_begin'); $this->view = Think::instance('View'); if(method_exists($this,'_initialize')) $this->_initialize(); } protected function getActionName() { if(empty($this->name)) { $this->name = substr(get_class($this),0,-6); } return $this->name; } protected function isAjax() { if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) { if('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) return true; } if(!empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) return true; return false; } protected function display($templateFile='',$charset='',$contentType='') { $this->view->display($templateFile,$charset,$contentType); } protected function fetch($templateFile='') { return $this->view->fetch($templateFile); } protected function buildHtml($htmlfile='',$htmlpath='',$templateFile='') { $content = $this->fetch($templateFile); $htmlpath = !empty($htmlpath)?$htmlpath:HTML_PATH; $htmlfile = $htmlpath.$htmlfile.C('HTML_FILE_SUFFIX'); if(!is_dir(dirname($htmlfile))) mk_dir(dirname($htmlfile)); if(false === file_put_contents($htmlfile,$content)) throw_exception(L('_CACHE_WRITE_ERROR_').':'.$htmlfile); return $content; } protected function assign($name,$value='') { $this->view->assign($name,$value); } public function __set($name,$value) { $this->view->assign($name,$value); } public function __get($name) { return $this->view->get($name); } public function __call($method,$args) { if( 0 === strcasecmp($method,ACTION_NAME)) { if(method_exists($this,'_empty')) { $this->_empty($method,$args); }elseif(file_exists_case(C('TEMPLATE_NAME'))){ $this->display(); }elseif(function_exists('__hack_action')) { __hack_action(); }elseif(APP_DEBUG) { throw_exception(L('_ERROR_ACTION_').ACTION_NAME); }else{ if(C('LOG_EXCEPTION_RECORD')) Log::write(L('_ERROR_ACTION_').ACTION_NAME); send_http_status(404); exit; } }else{ switch(strtolower($method)) { case 'ispost': case 'isget': case 'ishead': case 'isdelete': case 'isput': return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method,2)); case '_get': $input =& $_GET;break; case '_post':$input =& $_POST;break; case '_put': parse_str(file_get_contents('php://input'), $input);break; case '_request': $input =& $_REQUEST;break; case '_session': $input =& $_SESSION;break; case '_cookie': $input =& $_COOKIE;break; case '_server': $input =& $_SERVER;break; case '_globals': $input =& $GLOBALS;break; default: throw_exception(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); } if(isset($input[$args[0]])) { $data = $input[$args[0]]; $fun = $args[1]?$args[1]:C('DEFAULT_FILTER'); $data = $fun($data); }else{ $data = isset($args[2])?$args[2]:NULL; } return $data; } } protected function error($message,$jumpUrl='',$ajax=false) { $this->dispatchJump($message,0,$jumpUrl,$ajax); } protected function success($message,$jumpUrl='',$ajax=false) { $this->dispatchJump($message,1,$jumpUrl,$ajax); } protected function ajaxReturn($data,$info='',$status=1,$type='') { $result = array(); $result['status'] = $status; $result['info'] = $info; $result['data'] = $data; if(method_exists($this,'ajaxAssign')) $this->ajaxAssign($result); if(empty($type)) $type = C('DEFAULT_AJAX_RETURN'); if(strtoupper($type)=='JSON') { header('Content-Type:text/html; charset=utf-8'); exit(json_encode($result)); }elseif(strtoupper($type)=='XML'){ header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($result)); }elseif(strtoupper($type)=='EVAL'){ header('Content-Type:text/html; charset=utf-8'); exit($data); }else{ } } protected function redirect($url,$params=array(),$delay=0,$msg='') { $url = U($url,$params); redirect($url,$delay,$msg); } private function dispatchJump($message,$status=1,$jumpUrl='',$ajax=false) { if($ajax || $this->isAjax()) $this->ajaxReturn($ajax,$message,$status); if(!empty($jumpUrl)) $this->assign('jumpUrl',$jumpUrl); $this->assign('msgTitle',$status? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); if($this->view->get('closeWin')) $this->assign('jumpUrl','javascript:window.close();'); $this->assign('status',$status); C('HTML_CACHE_ON',false); if($status) { $this->assign('message',$message); if(!$this->view->get('waitSecond')) $this->assign('waitSecond','1'); if(!$this->view->get('jumpUrl')) $this->assign("jumpUrl",$_SERVER["HTTP_REFERER"]); $this->display(C('TMPL_ACTION_SUCCESS')); }else{ $this->assign('error',$message); if(!$this->view->get('waitSecond')) $this->assign('waitSecond','3'); if(!$this->view->get('jumpUrl')) $this->assign('jumpUrl',"javascript:history.back(-1);"); $this->display(C('TMPL_ACTION_ERROR')); exit ; } } public function __destruct() { if(C('LOG_RECORD')) Log::save(); tag('action_end'); } } class View { protected $tVar = array(); public function assign($name,$value=''){ if(is_array($name)) { $this->tVar = array_merge($this->tVar,$name); }elseif(is_object($name)){ foreach($name as $key =>$val) $this->tVar[$key] = $val; }else { $this->tVar[$name] = $value; } } public function get($name){ if(isset($this->tVar[$name])) return $this->tVar[$name]; else return false; } public function getAllVar(){ return $this->tVar; } public function traceVar(){ foreach ($this->tVar as $name=>$val){ dump($val,1,'['.$name.']<br/>'); } } public function display($templateFile='',$charset='',$contentType='') { G('viewStartTime'); tag('view_begin',$templateFile); $content = $this->fetch($templateFile); $this->show($content,$charset,$contentType); tag('view_end'); } public function show($content,$charset='',$contentType=''){ if(empty($charset)) $charset = C('DEFAULT_CHARSET'); if(empty($contentType)) $contentType = C('TMPL_CONTENT_TYPE'); header('Content-Type:'.$contentType.'; charset='.$charset); header('Cache-control: private'); header('X-Powered-By:ThinkPHP'); echo $content; } public function fetch($templateFile='') { tag('view_template',$templateFile); if(!is_file($templateFile)) return NULL; ob_start(); ob_implicit_flush(0); if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { extract($this->tVar, EXTR_OVERWRITE); include $templateFile; }else{ $params = array('var'=>$this->tVar,'file'=>$templateFile); tag('view_parse',$params); } $content = ob_get_clean(); tag('view_filter',$content); return $content; } } function fieldoption($fields, $value = null, $space = '') { $options = explode("\n", $fields['setup']['options']); foreach ($options as $r) { $v = explode("|", $r); $k = trim($v[1]); $optionsarr[$k] = $v[0]; } if (isset($value)) { if (strpos($value, ',')) { $value = explode(",", $value); $data = array(); foreach ((array) $value as $val) { $data[] = $optionsarr[$val]; } if ($space != '') { return implode(stripcslashes($space), $data); } else { return $data; } } else { return $optionsarr[$value]; } } else { return $optionsarr; } } function get_arrparentid($pid, $array = array(), $arrparentid = '') { if (!is_array($array) || !isset($array[$pid])) return $pid; $parentid = $array[$pid]['parentid']; $arrparentid = $arrparentid ? $parentid . ',' . $arrparentid : $parentid; if ($parentid) { $arrparentid = get_arrparentid($parentid, $array, $arrparentid); } else { $data = array(); $data['bid'] = $pid; $data['arrparentid'] = $arrparentid; } return $arrparentid; } function getform($form, $info, $value = '') { return $form->$info['type']($info, $value); } function getvalidate($info) { $validate_data = array(); if ($info['minlength']) $validate_data['minlength'] = ' minlength:' . $info['minlength']; if ($info['maxlength']) $validate_data['maxlength'] = ' maxlength:' . $info['maxlength']; if ($info['required']) $validate_data['required'] = ' required:true'; if ($info['pattern']) $validate_data['pattern'] = ' ' . $info['pattern'] . ':true'; if ($info['errormsg']) $errormsg = ' title="' . $info['errormsg'] . '"'; $validate = implode(',', $validate_data); $validate = $validate ? 'validate="' . $validate . '" ' : ''; $parseStr = $validate . $errormsg; return $parseStr; } function sendmail($tomail, $subject, $body, $config = '') { if (!$config) $config = F('Config'); import("@.ORG.PHPMailer"); $mail = new PHPMailer(); if ($config['mail_type'] == 1) { $mail->IsSMTP(); } elseif ($config['mail_type'] == 2) { $mail->IsMail(); } else { if ($config['sendmailpath']) { $mail->Sendmail = $config['mail_sendmail']; } else { $mail->Sendmail = ini_get('sendmail_path'); } $mail->IsSendmail(); } if ($config['mail_auth']) { $mail->SMTPAuth = true; } else { $mail->SMTPAuth = false; } $mail->PluginDir = LIB_PATH . "ORG/"; $mail->CharSet = 'utf-8'; $mail->SMTPDebug = false; $mail->Host = $config['mail_server']; $mail->Port = $config['mail_port']; $mail->Username = $config['mail_user']; $mail->Password = $config['mail_password']; $mail->SetFrom($config['mail_from'], $config['site_name']); $mail->AddAddress($tomail); $mail->IsHTML(true); $mail->Subject = $subject; $mail->Body = $body; if (!$mail->Send()) { return false; } else { return true; } } function delattach($map = '') { $model = M('Attachment'); $att = $model->field('aid,filepath')->where($map)->select(); $aids = array(); foreach ((array) $att as $key => $r) { $aids[] = $r['aid']; @unlink(__ROOT__ . $r['filepath']); } $r = $model->delete(implode(',', $aids)); return false !== $r ? true : false; } function template_file($module = '', $path = '', $ext = 'html') { $sysConfig = F('sys.config'); $path = $path ? $path : TMPL_PATH . 'Home/' . $sysConfig['DEFAULT_THEME'] . '/'; $tempfiles = dir_list($path, $ext); foreach ($tempfiles as $key => $file) { $dirname = basename($file); if ($module) { if (strstr($dirname, $module . '_')) { $arr[$key]['name'] = substr($dirname, 0, strrpos($dirname, '.')); $arr[$key]['value'] = substr($arr[$key]['name'], strpos($arr[$key]['name'], '_') + 1); $arr[$key]['filename'] = $dirname; $arr[$key]['filepath'] = $file; } } else { $arr[$key]['name'] = substr($dirname, 0, strrpos($dirname, '.')); $arr[$key]['value'] = substr($arr[$key]['name'], strpos($arr[$key]['name'], '_') + 1); $arr[$key]['filename'] = $dirname; $arr[$key]['filepath'] = $file; } } return $arr; } function fileext($filename) { return strtolower(trim(substr(strrchr($filename, '.'), 1, 10))); } function dir_path($path) { $path = str_replace('\\', '/', $path); if (substr($path, -1) != '/') $path = $path . '/'; return $path; } function dir_create($path, $mode = 0777) { if (is_dir($path)) return TRUE; $ftp_enable = 0; $path = dir_path($path); $temp = explode('/', $path); $cur_dir = ''; $max = count($temp) - 1; for ($i = 0; $i < $max; $i++) { $cur_dir .= $temp[$i] . '/'; if (@is_dir($cur_dir)) continue; @mkdir($cur_dir, 0777, true); @chmod($cur_dir, 0777); } return is_dir($path); } function dir_copy($fromdir, $todir) { $fromdir = dir_path($fromdir); $todir = dir_path($todir); if (!is_dir($fromdir)) return FALSE; if (!is_dir($todir)) dir_create($todir); $list = glob($fromdir . '*'); if (!empty($list)) { foreach ($list as $v) { $path = $todir . basename($v); if (is_dir($v)) { dir_copy($v, $path); } else { copy($v, $path); @chmod($path, 0777); } } } return TRUE; } function dir_list($path, $exts = '', $list = array()) { $path = dir_path($path); $files = glob($path . '*'); foreach ($files as $v) { $fileext = fileext($v); if (!$exts || preg_match("/\.($exts)/i", $v)) { $list[] = $v; if (is_dir($v)) { $list = dir_list($v, $exts, $list); } } } return $list; } function dir_tree($dir, $parentid = 0, $dirs = array()) { if ($parentid == 0) $id = 0; $list = glob($dir . '*'); foreach ($list as $v) { if (is_dir($v)) { $id++; $dirs[$id] = array('id' => $id, 'parentid' => $parentid, 'name' => basename($v), 'dir' => $v . '/'); $dirs = dir_tree($v . '/', $id, $dirs); } } return $dirs; } function dir_delete($dir) { $dir = dir_path($dir); if (!is_dir($dir)) return FALSE; $list = glob($dir . '*'); foreach ((array) $list as $v) { is_dir($v) ? dir_delete($v) : @unlink($v); } return @rmdir($dir); } function toDate($time, $format = 'Y-m-d H:i:s') { if (empty($time)) { return ''; } $format = str_replace('#', ':', $format); return date($format, $time); } function savecache($name = '', $id = '') { $Model = M($name); if ($name == 'Lang') { $list = $Model->order('listorder')->select(); $pkid = $Model->getPk(); $data = array(); foreach ($list as $key => $val) { $data [$val ['mark']] = $val; } F($name, $data); } elseif ($name == 'Module') { $list = $Model->order('listorder')->select(); $pkid = $Model->getPk(); $data = array(); foreach ($list as $key => $val) { $data [$val [$pkid]] = $val; $smalldata[$val['name']] = $val [$pkid]; } F($name, $data); F('Mod', $smalldata); } elseif ($name == 'Config') { $list = $Model->select(); $data = $sysdata = $temp = $memberconfig = array(); foreach ($list as $key => $r) { if ($r['groupid'] == 6) { $sysdata[$r['varname']] = $r['value']; } elseif ($r['groupid'] == 3) { if (APP_LANG) $memberconfig_temp[$r['lang']][$r['varname']] = $r['value']; else $memberconfig[$r['varname']] = $r['value']; }else { if (APP_LANG) if ($r['lang']) { $temp[$r['lang']][$r['varname']] = $r['value']; } else { $data[$r['varname']] = $r['value']; } else $data[$r['varname']] = $r['value']; } } if (APP_LANG) { $lang = F('Lang'); foreach ((array) $lang as $key => $r) { $data1 = array(); $data1 = array_merge($temp[$r['id']], $data); F('Config_' . $key, $data1); F('member.config_' . $key, $memberconfig_temp[$r['id']]); if (empty($data1['HOME_ISHTML'])) { @unlink('./index.html'); @unlink('./' . $key . '/index.html'); } } } else { F('Config', $data); F('member.config', $memberconfig); if (empty($data['HOME_ISHTML'])) @unlink('./index.html'); } F('sys.config', $sysdata); }elseif ($name == 'Category') { $data = $smalldata = $temp = array(); if (APP_LANG) { $lang = F('Lang'); foreach ((array) $lang as $key => $r) { $langid = $r['id']; if ($langid) { $lang = $key; $list = $Model->where('lang=' . $langid)->order('listorder')->select(); $pkid = $Model->getPk(); $data = array(); foreach ($list as $key => $val) { $data [$val [$pkid]] = $val; $smalldata[$val['catdir']] = $val [$pkid]; } F('Category_' . $lang, $data); F('Cat_' . $lang, $smalldata); } } } else { $list = $Model->order('listorder')->select(); $pkid = $Model->getPk(); $data = array(); foreach ($list as $key => $val) { $data [$val [$pkid]] = $val; $smalldata[$val['catdir']] = $val [$pkid]; } F($name, $data); F('Cat', $smalldata); } } elseif ($name == 'Field') { if ($id) { $list = $Model->order('listorder')->where('moduleid=' . $id)->select(); $pkid = 'field'; $data = array(); foreach ($list as $key => $val) { $data [$val [$pkid]] = $val; } $name = $id . '_' . $name; F($name, $data); } else { $module = F('Module'); foreach ($module as $key => $val) { savecache($name, $key); } } } elseif ($name == 'Dbsource') { $list = $Model->select(); $data = array(); foreach ($list as $key => $val) { $data [$val ['name']] = $val; } F($name, $data); } else { $list = $Model->order('listorder')->select(); $pkid = $Model->getPk(); $data = array(); foreach ($list as $key => $val) { $data [$val [$pkid]] = $val; } F($name, $data); if ($name == 'Urlrule') { $config = F('sys.config'); if ($config['URL_URLRULE']) routes_cache($config['URL_URLRULE']); } } return true; } function checkfield($fields) { foreach ($_POST as $key => $val) { $setup = $fields[$key]['setup']; if (!empty($fields[$key]['required']) && empty($_POST[$key])) return ''; if ($setup['multiple'] || $setup['inputtype'] == 'checkbox' || $fields[$key]['type'] == 'checkbox') { $_POST[$key] = implode(',', $_POST[$key]); } elseif ($fields[$key]['type'] == 'datetime') { $_POST[$key] = strtotime($_POST[$key]); } elseif ($fields[$key]['type'] == 'textarea') { $_POST[$key] = addslashes($_POST[$key]); } elseif ($fields[$key]['type'] == 'images' || $fields[$key]['type'] == 'files') { $name = $key . '_name'; $arrdata = array(); foreach ($_POST[$key] as $k => $res) { if (!empty($_POST[$key][$k])) $arrdata[] = $_POST[$key][$k] . '|' . $_POST[$name][$k]; } $_POST[$key] = implode(':::', $arrdata); }elseif ($fields[$key]['type'] == 'editor') { if (isset($_POST['add_description']) && $_POST['description'] == '' && isset($_POST['content'])) { $content = stripslashes($_POST['content']); $description_length = intval($_POST['description_length']); $_POST['description'] = str_cut(str_replace(array("\r\n", "\t", '[page]', '[/page]', '&ldquo;', '&rdquo;'), '', strip_tags($content)), $description_length); $_POST['description'] = addslashes($_POST['description']); } if (isset($_POST['auto_thumb']) && $_POST['thumb'] == '' && isset($_POST['content'])) { $content = $content ? $content : stripslashes($_POST['content']); $auto_thumb_no = intval($_POST['auto_thumb_no']) * 3; if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) { $_POST['thumb'] = $matches[$auto_thumb_no][0]; } } } } return $_POST; } function string2array($info) { if ($info == '') return array(); $info = stripcslashes($info); eval("\$r = $info;"); return $r; } function array2string($info) { if ($info == '') return ''; if (!is_array($info)) $string = stripslashes($info); foreach ($info as $key => $val) $string[$key] = stripslashes($val); return addslashes(var_export($string, TRUE)); } function rand_string($len = 6, $type = '', $addChars = '') { $str = ''; switch ($type) { case 0 : $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars; break; case 1 : $chars = str_repeat('0123456789', 3); break; case 2 : $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars; break; case 3 : $chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars; break; default : $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars; break; } if ($len > 10) { $chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5); } if ($type != 4) { $chars = str_shuffle($chars); $str = substr($chars, 0, $len); } else { for ($i = 0; $i < $len; $i++) { $str .= msubstr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1); } } return $str; } function sysmd5($str, $key = '', $type = 'sha1') { $key = $key ? $key : C('ADMIN_ACCESS'); return hash($type, $str . $key); } function pwdHash($password, $type = 'md5') { return hash($type, $password); } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya . md5($keya . $keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for ($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for ($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for ($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if ($operation == 'DECODE') { if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc . str_replace('=', '', base64_encode($result)); } } function str_cut($sourcestr, $cutlength, $suffix = '...') { $str_length = strlen($sourcestr); if ($str_length <= $cutlength) { return $sourcestr; } $returnstr = ''; $n = $i = $noc = 0; while ($n < $str_length) { $t = ord($sourcestr[$n]); if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $i = 1; $n++; $noc++; } elseif (194 <= $t && $t <= 223) { $i = 2; $n += 2; $noc += 2; } elseif (224 <= $t && $t <= 239) { $i = 3; $n += 3; $noc += 2; } elseif (240 <= $t && $t <= 247) { $i = 4; $n += 4; $noc += 2; } elseif (248 <= $t && $t <= 251) { $i = 5; $n += 5; $noc += 2; } elseif ($t == 252 || $t == 253) { $i = 6; $n += 6; $noc += 2; } else { $n++; } if ($noc >= $cutlength) { break; } } if ($noc > $cutlength) { $n -= $i; } $returnstr = substr($sourcestr, 0, $n); if (substr($sourcestr, $n, 6)) { $returnstr = $returnstr . $suffix; } return $returnstr; } function IP($ip = '', $file = 'UTFWry.dat') { import("@.ORG.IpLocation"); $iplocation = new IpLocation($file); $location = $iplocation->getlocation($ip); return $location; } function byte_format($input, $dec = 0) { $prefix_arr = array("B", "K", "M", "G", "T"); $value = round($input, $dec); $i = 0; while ($value > 1024) { $value /= 1024; $i++; } $return_str = round($value, $dec) . $prefix_arr[$i]; return $return_str; } function build_verify($length = 4, $mode = 1) { return rand_string($length, $mode); } function make_urlrule($url, $lang, $action, $MOREREQUEST = '') { preg_match_all("/{([\w\$]+)}/", $url, $matches); if (strstr($url, '{$parentdir') && C('URL_PATHINFO_DEPR') == '/') { if (APP_LANG) { foreach ((array) $lang as $r) { $Category = F('Category_' . $r); foreach ((array) $Category as $key => $r) { if ($r['parentid'] == 0) $pcatdir[] = $r['catdir']; } } }else { $Category = F('Category'); foreach ((array) $Category as $key => $r) { if ($r['parentid'] == 0) $pcatdir[] = $r['catdir']; } } unset($Category); $parent_rule = '(' . implode('|', $pcatdir) . ')\/'; } $REQUEST = str_replace(array('{$parentdir}', '{$module}', '{$moduleid}', '{$catdir}', '{$year}', '{$month}', '{$day}', '{$catid}', '{$id}', '{$page}'), array('', 'module', 'moduleid', 'catdir', 'year', 'month', 'day', 'catid', 'id', C('VAR_PAGE')), $matches[0]); $rule = str_replace(array('{$parentdir}', '{$module}', '{$moduleid}', '{$catdir}', '{$year}', '{$month}', '{$day}', '{$catid}', '{$id}', '{$page}', '/', C('URL_HTML_SUFFIX')), array('', '([A-Z]{1}[a-z]+)', '(\d+)', '([\w^_]+)', '(\d+)', '(\d+)', '(\d+)', '(\d+)', '(\d+)', '(\d+)', '\/', ''), $url); $i = 0; $j = 1; $k = 2; $n = 3; $m = 4; foreach ($REQUEST as $key => $r) { if ($r) { $i = $i + 1; $request .=$r . '=:' . $i . '&'; $j = $j + 1; $request_lang .=$r . '=:' . $j . '&'; $k = $k + 1; $request_lang_2 .=$r . '=:' . $k . '&'; $n = $n + 1; $request_lang_3 .=$r . '=:' . $n . '&'; } } if (APP_LANG) { $langrule = '(' . implode('|', $lang) . ')\/'; if ($parent_rule) { $data[] = '\'/^' . $langrule . $parent_rule . '([\w^_]+)\/' . $rule . '$/\' => \'Urlrule/' . $action . '?l=:1&parentdir=:2&' . $request_lang_3 . $MOREREQUEST . $langrequest . '\''; $data[] = '\'/^' . $langrule . $parent_rule . $rule . '$/\' => \'Urlrule/' . $action . '?l=:1&parentdir=:2&' . $request_lang_2 . $MOREREQUEST . $langrequest . '\''; $data[] = '\'/^' . $parent_rule . '([\w^_]+)\/' . $rule . '$/\' => \'Urlrule/' . $action . '?parentdir=:1&' . $request_lang_2 . $MOREREQUEST . $langrequest . '\''; $data[] = '\'/^' . $parent_rule . $rule . '$/\' => \'Urlrule/' . $action . '?parentdir=:1&' . $request_lang . $MOREREQUEST . $langrequest . '\''; if (strstr($url, '{$page')) { $data[] = '\'/^' . $langrule . $parent_rule . '(\d+)$/\' => \'Urlrule/' . $action . '?l=:1&catdir=:2&p=:3\''; $data[] = '\'/^' . $parent_rule . '(\d+)$/\' => \'Urlrule/' . $action . '?catdir=:1&p=:2\''; } else { $data[] = '\'/^' . $langrule . $parent_rule . '$/\' => \'Urlrule/' . $action . '?l=:1&catdir=:2\''; $data[] = '\'/^' . $parent_rule . '$/\' => \'Urlrule/' . $action . '?catdir=:1\''; } } else { $data[] = '\'/^' . $langrule . $rule . '$/\' => \'Urlrule/' . $action . '?l=:1&' . $request_lang . $MOREREQUEST . $langrequest . '\''; $data[] = '\'/^' . $rule . '$/\' => \'Urlrule/' . $action . '?' . $request . $MOREREQUEST . '\''; } $data = str_replace('\/$', '$', $data); $data = implode(",\n", $data); } else { if ($parent_rule) { $data[] = '\'/^' . $parent_rule . '([\w^_]+)\/' . $rule . '$/\' => \'Urlrule/' . $action . '?parentdir=:1&' . $request_lang_2 . $MOREREQUEST . $langrequest . '\''; $data[] = '\'/^' . $parent_rule . $rule . '$/\' => \'Urlrule/' . $action . '?parentdir=:1&' . $request_lang . $MOREREQUEST . $langrequest . '\''; if (strstr($url, '{$page')) { $data[] = '\'/^' . $parent_rule . '(\d+)$/\' => \'Urlrule/' . $action . '?catdir=:1&p=:2\''; } else { $data[] = '\'/^' . $parent_rule . '$/\' => \'Urlrule/' . $action . '?catdir=:1\''; } } else { $urlrule = '\'/^' . $rule . '$/\' => \'Urlrule/' . $action . '?' . $request . $MOREREQUEST . '\''; $data = str_replace('\/$', '$', $urlrule); } } return $data; } function routes_cache($URL_URLRULE = '') { $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags' . C('URL_PATHINFO_DEPR') . ':module' . C('URL_PATHINFO_DEPR') . ':tag' . C('URL_PATHINFO_DEPR') . ':p\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags' . C('URL_PATHINFO_DEPR') . ':tag' . C('URL_PATHINFO_DEPR') . ':p\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags' . C('URL_PATHINFO_DEPR') . ':module' . C('URL_PATHINFO_DEPR') . ':tag\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags' . C('URL_PATHINFO_DEPR') . ':p\d\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags' . C('URL_PATHINFO_DEPR') . ':tag\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\':l' . C('URL_PATHINFO_DEPR') . 'Tags\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags' . C('URL_PATHINFO_DEPR') . ':module' . C('URL_PATHINFO_DEPR') . ':tag' . C('URL_PATHINFO_DEPR') . ':p\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags' . C('URL_PATHINFO_DEPR') . ':tag' . C('URL_PATHINFO_DEPR') . ':p\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags' . C('URL_PATHINFO_DEPR') . ':module' . C('URL_PATHINFO_DEPR') . ':tag\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags' . C('URL_PATHINFO_DEPR') . ':p\d\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags' . C('URL_PATHINFO_DEPR') . ':tag\' => \'Home/Tags/index\',' . "\n"; $urlstr .= '\'Tags\' => \'Home/Tags/index\',' . "\n"; if (APP_LANG) { $Lang = F('Lang'); foreach ((array) $Lang as $key => $r) { $langarr[] = $key; } $urlstr .= '\'/^(' . implode('|', $langarr) . ')$/\' => \'Index/index?l=:1\',' . "\n"; } $URL_URLRULE = $URL_URLRULE ? $URL_URLRULE : C('URL_URLRULE'); $urlrule = is_array($URL_URLRULE) ? $URL_URLRULE : explode(':::', $URL_URLRULE); $list = explode('|', $urlrule[1]); $show = explode('|', $urlrule[0]); $listurls[] = make_urlrule($show[1], $langarr, 'show'); $listurls[] = make_urlrule($show[0], $langarr, 'show'); $listurls[] = make_urlrule($list[1], $langarr, 'index'); $listurls[] = make_urlrule($list[0], $langarr, 'index'); $url = implode(",\n", $listurls); file_put_contents(DATA_PATH . 'Routes.php', "<?php\nreturn array(\n" . $urlstr . $url . "\n);\n?>"); if (is_file(RUNTIME_PATH . '~runtime.php')) @unlink(RUNTIME_PATH . '~runtime.php'); if (is_file(RUNTIME_PATH . '~allinone.php')) @unlink(RUNTIME_PATH . '~allinone.php'); } function HOMEURL($lang) { if (C('URL_M') == 1) $index = '/index.php/'; $lang = C('URL_LANG') != $lang ? $lang : ''; if (C('URL_M') > 0) { $url = $lang ? __ROOT__ . $index . $lang . '/' : __ROOT__ . '/'; } else { $url = $lang ? __ROOT__ . '/index.php?l=' . $lang : __ROOT__ . '/'; } return $url; } function URL($url = '', $params = array()) { if (APP_LANG) $lang = getlang(); if (!empty($url)) { list($path, $query) = explode('?', $url); list($group, $a) = explode('/', $path); list($g, $m) = explode('-', $group); $params = http_build_query($params); $params = !empty($params) ? '&' . $params : ''; $query = !empty($query) ? '&' . $query : ''; if ($lang) $langurl = '&l=' . $lang; if (strcasecmp($g, 'Home') == 0) { $url = __ROOT__ . '/index.php?m=' . $m . '&a=' . $a . $query . $params . $langurl; } else { $url = __ROOT__ . '/index.php?g=' . $g . '&m=' . $m . '&a=' . $a . $query . $params . $langurl; } } else { if (C('URL_M') == 1) $index = '/index.php/'; if (C('URL_M') > 0) { $url = $lang ? __ROOT__ . $index . $lang . '/' : __ROOT__ . '/'; } else { $url = $lang ? __ROOT__ . '/index.php?l=' . $lang : __ROOT__ . '/'; } } return $url; } function TAGURL($data, $p = '') { $index = C('URL_M') == 1 ? __ROOT__ . 'index.php/' : __ROOT__ . '/'; if (APP_LANG) $lang = getlang(); if (C('URL_M') == 0) { if ($data['moduleid'] > 0 && $data['moduleid'] != 2) $params['moduleid'] = $data['moduleid']; if ($data['slug']) $params['tag'] = $data['slug']; if ($lang) $params['l'] = $lang; $url = URL('Home-Tags/index', $params); if ($p) $url = $url . '&p={$page}'; }else { $tag = $data['slug'] ? '/' . $data['slug'] : ''; $module = ($data['moduleid'] > 0 && $data['moduleid'] != 2) ? '/' . $data['module'] : ''; $langurl = $lang ? $lang . '/' : ''; $url = $index . $langurl . 'Tags' . $module . $tag . '/'; if ($p) $url = $url . '{$page}' . C('URL_HTML_SUFFIX'); } return $url; } function getlang($have = '') { if ($have) { if (strcasecmp(GROUP_NAME, 'Admin') == 0) $lang = LANG_NAME; else $lang = $_REQUEST['l'] ? $_REQUEST['l'] : C('URL_LANG'); }else { if (strcasecmp(GROUP_NAME, 'Admin') == 0) $lang = C('URL_LANG') != LANG_NAME ? LANG_NAME : ''; else $lang = $_REQUEST['l'] && C('URL_LANG') != $_REQUEST['l'] ? $_REQUEST['l'] : ''; } return $lang; } function geturl($cat, $data = '', $Urlrule = '') { $id = $data['id']; $URL_MODEL = C('URL_M'); if (APP_LANG) $lang = getlang(); $parentdir = $cat['parentdir']; $catdir = $cat['catdir']; $year = date('Y', $data['createtime']); $month = date('m', $data['createtime']); $day = date('d', $data['createtime']); $module = $cat['module']; $moduleid = $cat['moduleid']; $catid = $cat['id']; if ($cat['ishtml']) { if ($cat['urlruleid'] && $Urlrule) { $showurlrule = $Urlrule[$cat['urlruleid']]['showurlrule']; $listurlrule = $Urlrule[$cat['urlruleid']]['listurlrule']; } else { echo 'This cat has not urlruleid or no Urlrule.'; exit; } } else { if ($URL_MODEL == 0) { $langurl = $lang ? '&l=' . LANG_NAME : ''; if ($id) { $url[] = U("Home/$cat[module]/show?id=$id" . $langurl); $url[] = U("Home/$cat[module]/show?id=" . $id . $langurl . '&' . C('VAR_PAGE') . '={$page}'); } else { $url[] = U("Home/$cat[module]/index?id=$cat[id]" . $langurl); $url[] = U("Home/$cat[module]/index?id=$cat[id]$langurl&" . C('VAR_PAGE') . '={$page}'); } $urls = str_replace('g=Admin&', '', $url); $urls = str_replace('g=Home&', '', $url); } else { $urlrule = explode(':::', C('URL_URLRULE')); $showurlrule = $urlrule[0]; $listurlrule = $urlrule[1]; } } if (empty($urls)) { $index = $URL_MODEL == 1 ? __ROOT__ . '/index.php/' : __ROOT__ . '/'; $langurl = $lang ? $lang . '/' : ''; if ($id) { $urls = str_replace(array('{$parentdir}', '{$module}', '{$moduleid}', '{$catdir}', '{$year}', '{$month}', '{$day}', '{$catid}', '{$id}'), array($parentdir, $module, $moduleid, $catdir, $year, $month, $day, $catid, $id), $showurlrule); } else { $urls = str_replace(array('{$parentdir}', '{$module}', '{$moduleid}', '{$catdir}', '{$year}', '{$month}', '{$day}', '{$catid}', '{$id}'), array($parentdir, $module, $moduleid, $catdir, $year, $month, $day, $catid, $id), $listurlrule); } $urls = explode('|', $urls); $urls[0] = $index . $langurl . $urls[0]; $urls[1] = $index . $langurl . $urls[1]; } return $urls; } function content_pages($num, $p, $pageurls) { $multipage = ''; $page = 11; $offset = 4; $pages = $num; $from = $p - $offset; $to = $p + $offset; $more = 0; if ($page >= $pages) { $from = 2; $to = $pages - 1; } else { if ($from <= 1) { $to = $page - 1; $from = 2; } elseif ($to >= $pages) { $from = $pages - ($page - 2); $to = $pages - 1; } $more = 1; } if ($p > 0) { $perpage = $p == 1 ? 1 : $p - 1; if ($perpage == 1) { $multipage .= '<a class="a1" href="' . $pageurls[$perpage][0] . '">' . L('previous') . '</a>'; } else { $multipage .= '<a class="a1" href="' . $pageurls[$perpage][1] . '">' . L('previous') . '</a>'; } if ($p == 1) { $multipage .= ' <span>1</span>'; } elseif ($p > 6 && $more) { $multipage .= ' <a href="' . $pageurls[1][0] . '">1</a>..'; } else { $multipage .= ' <a href="' . $pageurls[1][0] . '">1</a>'; } } for ($i = $from; $i <= $to; $i++) { if ($i != $p) { $multipage .= ' <a href="' . $pageurls[$i][1] . '">' . $i . '</a>'; } else { $multipage .= ' <span>' . $i . '</span>'; } } if ($p < $pages) { if ($p < $pages - 5 && $more) { $multipage .= ' ..<a href="' . $pageurls[$pages][1] . '">' . $pages . '</a> <a class="a1" href="' . $pageurls[$p + 1][1] . '">' . L('next') . '</a>'; } else { $multipage .= ' <a href="' . $pageurls[$pages][1] . '">' . $pages . '</a> <a class="a1" href="' . $pageurls[$p + 1][1] . '">' . L('next') . '</a>'; } } elseif ($p == $pages) { $multipage .= ' <span>' . $pages . '</span> <a class="a1" href="' . $pageurls[$p][1] . '">' . L('next') . '</a>'; } return $multipage; } function thumb($f, $tw = 300, $th = 300, $autocat = 0, $nopic = 'nopic.jpg', $t = '') { if (strstr($f, '://')) return $f; if (empty($f)) return __ROOT__ . '/Public/Images/' . $nopic; $f = '.' . str_replace(__ROOT__, '', $f); $temp = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); list($fw, $fh, $tmp) = getimagesize($f); if (empty($t)) { if ($fw > $tw && $fh > $th) { $pathinfo = pathinfo($f); $t = $pathinfo['dirname'] . '/thumb_' . $tw . '_' . $th . '_' . $pathinfo['basename']; if (is_file($t)) { return __ROOT__ . substr($t, 1); } } else { return __ROOT__ . substr($f, 1); } } if (!$temp[$tmp]) { return false; } if ($autocat) { if ($fw / $tw > $fh / $th) { $fw = $tw * ($fh / $th); } else { $fh = $th * ($fw / $tw); } } else { $scale = min($tw / $fw, $th / $fh); if ($scale >= 1) { $tw = $fw; $th = $fh; } else { $tw = (int) ($fw * $scale); $th = (int) ($fh * $scale); } } $tmp = $temp[$tmp]; $infunc = "imagecreatefrom$tmp"; $outfunc = "image$tmp"; $fimg = $infunc($f); if ($tmp != 'gif' && function_exists('imagecreatetruecolor')) { $timg = imagecreatetruecolor($tw, $th); } else { $timg = imagecreate($tw, $th); } if (function_exists('imagecopyresampled')) imagecopyresampled($timg, $fimg, 0, 0, 0, 0, $tw, $th, $fw, $fh); else imagecopyresized($timg, $fimg, 0, 0, 0, 0, $tw, $th, $fw, $fh); if ($tmp == 'gif' || $tmp == 'png') { $background_color = imagecolorallocate($timg, 0, 255, 0); imagecolortransparent($timg, $background_color); } $outfunc($timg, $t); imagedestroy($timg); imagedestroy($fimg); return __ROOT__ . substr($t, 1); } function ubb2html($sUBB) { $sHtml = $sUBB; global $emotPath, $cnum, $arrcode, $bUbb2htmlFunctionInit; $cnum = 0; $arrcode = array(); $emotPath = '../xheditor_emot/'; if (!$bUbb2htmlFunctionInit) { function saveCodeArea($match) { global $cnum, $arrcode; $cnum++; $arrcode[$cnum] = $match[0]; return "[\tubbcodeplace_" . $cnum . "\t]"; } } $sHtml = preg_replace_callback('/\[code\s*(?:=\s*((?:(?!")[\s\S])+?)(?:"[\s\S]*?)?)?\]([\s\S]*?)\[\/code\]/i', 'saveCodeArea', $sHtml); $sHtml = preg_replace("/&/", '&amp;', $sHtml); $sHtml = preg_replace("/</", '&lt;', $sHtml); $sHtml = preg_replace("/>/", '&gt;', $sHtml); $sHtml = preg_replace("/\r?\n/", '<br />', $sHtml); $sHtml = preg_replace("/\[(\/?)(b|u|i|s|sup|sub)\]/i", '<$1$2>', $sHtml); $sHtml = preg_replace('/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i', '<span style="color:$1;">', $sHtml); if (!$bUbb2htmlFunctionInit) { function getSizeName($match) { $arrSize = array('10px', '13px', '16px', '18px', '24px', '32px', '48px'); if (preg_match("/^\d+$/", $match[1])) $match[1] = $arrSize[$match[1] - 1]; return '<span style="font-size:' . $match[1] . ';">'; } } $sHtml = preg_replace_callback('/\[size\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i', 'getSizeName', $sHtml); $sHtml = preg_replace('/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i', '<span style="font-family:$1;">', $sHtml); $sHtml = preg_replace('/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i', '<span style="background-color:$1;">', $sHtml); $sHtml = preg_replace("/\[\/(color|size|font|back)\]/i", '</span>', $sHtml); for ($i = 0; $i < 3; $i++) $sHtml = preg_replace('/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/', '<p align="$1">$2</p>', $sHtml); $sHtml = preg_replace('/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/i', '<img src="$1" alt="" />', $sHtml); if (!$bUbb2htmlFunctionInit) { function getImg($match) { $alt = $match[1]; $p1 = $match[2]; $p2 = $match[3]; $p3 = $match[4]; $src = $match[5]; $a = $p3 ? $p3 : (!is_numeric($p1) ? $p1 : ''); return '<img src="' . $src . '" alt="' . $alt . '"' . (is_numeric($p1) ? ' width="' . $p1 . '"' : '') . (is_numeric($p2) ? ' height="' . $p2 . '"' : '') . ($a ? ' align="' . $a . '"' : '') . ' />'; } } $sHtml = preg_replace_callback('/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/i', 'getImg', $sHtml); if (!$bUbb2htmlFunctionInit) { function getEmot($match) { global $emotPath; $arr = split(',', $match[1]); if (!isset($arr[1])) { $arr[1] = $arr[0]; $arr[0] = 'default'; } $path = $emotPath . $arr[0] . '/' . $arr[1] . '.gif'; return '<img src="' . $path . '" alt="' . $arr[1] . '" />'; } } $sHtml = preg_replace_callback('/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/i', 'getEmot', $sHtml); $sHtml = preg_replace('/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/i', '<a href="$1">$1</a>', $sHtml); $sHtml = preg_replace('/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/i', '<a href="$1">$2</a>', $sHtml); $sHtml = preg_replace('/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/i', '<a href="mailto:$1">$1</a>', $sHtml); $sHtml = preg_replace('/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/i', '<a href="mailto:$1">$2</a>', $sHtml); $sHtml = preg_replace("/\[quote\]([\s\S]*?)\[\/quote\]/i", '<blockquote>$1</blockquote>', $sHtml); if (!$bUbb2htmlFunctionInit) { function getFlash($match) { $w = $match[1]; $h = $match[2]; $url = $match[3]; if (!$w) $w = 480;if (!$h) $h = 400; return '<embed type="application/x-shockwave-flash" src="' . $url . '" wmode="opaque" quality="high" bgcolor="#ffffff" menu="false" play="true" loop="true" width="' . $w . '" height="' . $h . '" />'; } } $sHtml = preg_replace_callback('/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/i', 'getFlash', $sHtml); if (!$bUbb2htmlFunctionInit) { function getMedia($match) { $w = $match[1]; $h = $match[2]; $play = $match[3]; $url = $match[4]; if (!$w) $w = 480;if (!$h) $h = 400; return '<embed type="application/x-mplayer2" src="' . $url . '" enablecontextmenu="false" autostart="' . ($play == '1' ? 'true' : 'false') . '" width="' . $w . '" height="' . $h . '" />'; } } $sHtml = preg_replace_callback('/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/i', 'getMedia', $sHtml); if (!$bUbb2htmlFunctionInit) { function getTable($match) { return '<table' . (isset($match[1]) ? ' width="' . $match[1] . '"' : '') . (isset($match[2]) ? ' bgcolor="' . $match[2] . '"' : '') . '>'; } } $sHtml = preg_replace_callback('/\[table\s*(?:=(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/i', 'getTable', $sHtml); if (!$bUbb2htmlFunctionInit) { function getTR($match) { return '<tr' . (isset($match[1]) ? ' bgcolor="' . $match[1] . '"' : '') . '>'; } } $sHtml = preg_replace_callback('/\[tr\s*(?:=(\s*[^\]"]+))?(?:"[^\]]*?)?\s*\]/i', 'getTR', $sHtml); if (!$bUbb2htmlFunctionInit) { function getTD($match) { $col = isset($match[1]) ? $match[1] : 0; $row = isset($match[2]) ? $match[2] : 0; $w = isset($match[3]) ? $match[3] : null; return '<td' . ($col > 1 ? ' colspan="' . $col . '"' : '') . ($row > 1 ? ' rowspan="' . $row . '"' : '') . ($w ? ' width="' . $w . '"' : '') . '>'; } } $sHtml = preg_replace_callback("/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/i", 'getTD', $sHtml); $sHtml = preg_replace("/\[\/(table|tr|td)\]/i", '</$1>', $sHtml); $sHtml = preg_replace("/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/i", '<li>$1</li>', $sHtml); if (!$bUbb2htmlFunctionInit) { function getUL($match) { $str = '<ul'; if (isset($match[1])) $str.=' type="' . $match[1] . '"'; return $str . '>'; } } $sHtml = preg_replace_callback('/\[list\s*(?:=\s*([^\]"]+))?(?:"[^\]]*?)?\s*\]/i', 'getUL', $sHtml); $sHtml = preg_replace("/\[\/list\]/i", '</ul>', $sHtml); $sHtml = preg_replace("/\[hr\/\]/i", '<hr />', $sHtml); for ($i = 1; $i <= $cnum; $i++) $sHtml = str_replace("[\tubbcodeplace_" . $i . "\t]", $arrcode[$i], $sHtml); if (!$bUbb2htmlFunctionInit) { function fixText($match) { $text = $match[2]; $text = preg_replace("/\t/", '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $text); $text = preg_replace("/ /", '&nbsp;', $text); return $match[1] . $text; } } $sHtml = preg_replace_callback('/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/i', 'fixText', $sHtml); $bUbb2htmlFunctionInit = true; return $sHtml; } function Pinyin($_String) { $_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha" . "|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|" . "cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er" . "|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui" . "|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang" . "|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang" . "|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue" . "|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne" . "|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" . "|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang" . "|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|" . "she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|" . "tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu" . "|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you" . "|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|" . "zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo"; $_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990" . "|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725" . "|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263" . "|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003" . "|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697" . "|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211" . "|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922" . "|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468" . "|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664" . "|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407" . "|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959" . "|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652" . "|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369" . "|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128" . "|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914" . "|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645" . "|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149" . "|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087" . "|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658" . "|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340" . "|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888" . "|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585" . "|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847" . "|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055" . "|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780" . "|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274" . "|-10270|-10262|-10260|-10256|-10254"; $_TDataKey = explode('|', $_DataKey); $_TDataValue = explode('|', $_DataValue); $_Data = array_combine($_TDataKey, $_TDataValue); arsort($_Data); reset($_Data); $_String = auto_charset($_String, 'utf-8', 'gbk'); $_Res = ''; for ($i = 0; $i < strlen($_String); $i++) { $_P = ord(substr($_String, $i, 1)); if ($_P > 160) { $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P * 256 + $_Q - 65536; } $_Res .= _Pinyin($_P, $_Data); } return preg_replace("/[^a-z0-9]*/", '', $_Res); } function auto_charset($fContents, $from = 'gbk', $to = 'utf-8') { $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; if (strtoupper($from) === strtoupper($to) || empty($fContents) || (is_scalar($fContents) && !is_string($fContents))) { return $fContents; } if (is_string($fContents)) { if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($fContents, $to, $from); } elseif (function_exists('iconv')) { return iconv($from, $to, $fContents); } else { return $fContents; } } elseif (is_array($fContents)) { foreach ($fContents as $key => $val) { $_key = auto_charset($key, $from, $to); $fContents[$_key] = auto_charset($val, $from, $to); if ($key != $_key) unset($fContents[$key]); } return $fContents; } else { return $fContents; } } function _Pinyin($_Num, $_Data) { if ($_Num > 0 && $_Num < 160) return chr($_Num); elseif ($_Num < -20319 || $_Num > -10247) return ''; else { foreach ($_Data as $k => $v) { if ($v <= $_Num) break; } return $k; } } function return_url($code) { $config = APP_LANG ? F('Config_' . LANG_NAME) : F('Config'); return $config['site_url'] . '/index.php?g=User&m=Pay&a=respond&code=' . $code; } function order_pay_status($sn, $value) { $cart['status'] = 1; $cart['pay_status'] = $value; if ($value == 2) $cart['pay_time'] = time(); $r = M('Order')->where("sn='{$sn}'")->save($cart); return $r; } L(array ( ));C(array ( 'app_status' => 'debug', 'app_file_case' => false, 'app_autoload_path' => '', 'app_tags_on' => true, 'app_sub_domain_deploy' => false, 'app_sub_domain_rules' => array ( ), 'app_sub_domain_deny' => array ( ), 'app_group_list' => 'Home,Admin,User', 'cookie_expire' => '', 'cookie_domain' => '', 'cookie_path' => '/', 'cookie_prefix' => 'joyeasy_', 'default_app' => '@', 'default_lang' => 'cn', 'default_theme' => 'Default', 'default_group' => 'Home', 'default_module' => 'Index', 'default_action' => 'index', 'default_charset' => 'utf-8', 'default_timezone' => 'PRC', 'default_ajax_return' => 'JSON', 'default_filter' => 'htmlspecialchars', 'db_type' => 'mysql', 'db_host' => 'localhost', 'db_name' => 'wode', 'db_user' => 'wode', 'db_pwd' => '1qaz2wsx', 'db_port' => '3306', 'db_prefix' => 'wode_', 'db_fieldtype_check' => true, 'db_fields_cache' => false, 'db_charset' => 'utf8', 'db_deploy_type' => 0, 'db_rw_separate' => false, 'db_master_num' => 1, 'db_sql_build_cache' => false, 'db_sql_build_queue' => 'file', 'db_sql_build_length' => 20, 'data_cache_time' => 0, 'data_cache_compress' => false, 'data_cache_check' => false, 'data_cache_type' => 'File', 'data_cache_path' => './Cache/Temp/', 'data_cache_subdir' => false, 'data_path_level' => 1, 'error_message' => '您浏览的页面暂时发生了错误！请稍后再试～', 'error_page' => '', 'show_error_msg' => false, 'log_record' => false, 'log_type' => 3, 'log_dest' => '', 'log_extra' => '', 'log_level' => 'EMERG,ALERT,CRIT,ERR', 'log_file_size' => 2097152, 'log_exception_record' => false, 'session_auto_start' => true, 'session_options' => array ( ), 'session_type' => '', 'session_prefix' => '', 'var_session_id' => 'session_id', 'tmpl_content_type' => 'text/html', 'tmpl_action_error' => './Joyeasy//Tpl/Public/success.html', 'tmpl_action_success' => './Joyeasy//Tpl/Public/success.html', 'tmpl_exception_file' => './Joyeasy//Tpl/Public/exception.html', 'tmpl_detect_theme' => false, 'tmpl_template_suffix' => '.html', 'tmpl_file_depr' => '_', 'url_case_insensitive' => false, 'url_model' => '0', 'url_pathinfo_depr' => '/', 'url_pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', 'url_html_suffix' => '.html', 'var_group' => 'g', 'var_module' => 'm', 'var_action' => 'a', 'var_ajax_submit' => 'ajax', 'var_pathinfo' => 's', 'var_url_params' => '_URL_', 'var_template' => 't', 'show_page_trace' => false, 'url_router_on' => true, 'lang_switch_on' => true, 'lang_list' => 'cn,zh-cn,en', 'taglib_load' => true, 'taglib_pre_load' => 'joyeasy', 'var_page' => 'p', 'layout_home_on' => '1', 'url_route_rules' => NULL, 'page_listrows' => '10', 'token_on' => '1', 'token_name' => '__hash__', 'tmpl_cache_on' => '0', 'tmpl_cache_time' => '-1', 'html_cache_on' => '0', 'html_cache_time' => '60', 'html_read_type' => '0', 'html_file_suffix' => '.html', 'admin_access' => '8e7e9296160c755fa6f1c4dbc445c890', 'home_ishtml' => '1', 'url_urlrule' => '{$catdir}/show/{$id}.html|{$catdir}/show/{$id}_{$page}.html:::{$catdir}/|{$catdir}/{$page}.html', 'layout_on' => '1', 'extends' => array ( 'app_init' => array ( ), 'app_begin' => array ( 0 => 'ReadHtmlCache', ), 'route_check' => array ( 0 => 'CheckRoute', ), 'app_end' => array ( ), 'path_info' => array ( ), 'action_begin' => array ( ), 'action_end' => array ( ), 'view_begin' => array ( ), 'view_template' => array ( 0 => 'LocationTemplate', ), 'view_parse' => array ( 0 => 'ParseTemplate', ), 'view_filter' => array ( 0 => 'ContentReplace', 1 => 'TokenBuild', 2 => 'WriteHtmlCache', 3 => 'ShowRuntime', ), 'view_end' => array ( 0 => 'ShowPageTrace', ), ), 'tags' => array ( 'app_begin' => array ( 0 => 'CheckLang', ), 'app_init' => array ( 0 => 'CheckLang', ), ), ));G('loadTime');Think::Start();